Note that there are some explanatory texts on larger screens.

plurals
  1. POcenter text in a listview
    primarykey
    data
    text
    <p>I'm finding it impossible to center the text in my listview, tried wrap_content and layout_gravity=center on virtually everything vet the text doesn't move</p> <p>here's my class agenceEco</p> <pre><code>package com.blabla; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import android.app.Activity; import android.app.ListActivity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.*; public class agenceEco extends Activity { ListView myList; String[] listContent = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.agence); myList = (ListView)findViewById(R.id.liste_agences); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.simple_list_item, listContent); myList.setAdapter(adapter); myList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; myAdapter, View myView, int myItemInt, long mylng) { String selectedFromList = (String)(myList.getItemAtPosition(myItemInt)); Toast.makeText(getBaseContext(),selectedFromList,Toast.LENGTH_SHORT).show(); } }); } } </code></pre> <p>Heres simple_list_item.xml</p> <pre><code>&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:paddingTop="10dip" android:paddingBottom="10dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="@color/black" android:background="@color/white" android:gravity="center" /&gt; </code></pre> <p>here's agence.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/white" android:layout_gravity="center_horizontal"&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/black"&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/white" android:text=" " android:layout_gravity="center" /&gt; &lt;TextView android:id="@+id/txt_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/white" android:text="Choix de l'agence" android:layout_gravity="center" android:textStyle="bold" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text=" " android:layout_gravity="center" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text=" " android:layout_gravity="center" /&gt; &lt;ListView android:id="@+id/liste_agences" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/white" android:layout_gravity="center_horizontal" &gt;&lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload