Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: listview item width fill_parent doesnt work

I have search the internet and so on but couldnt find a solution for my problem. I'm creating a listview and setting an adapter:

myListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, theStringList));

theStringList is a simple LinkedList<String> with items.

and the android.R.layout.simple_list_item_1 is:

<TextView android:id="@android:id/text1" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:textAppearance="?android:attr/textAppearanceLarge" 
  android:gravity="center_vertical" 
  android:paddingLeft="6dip" 
  android:minHeight="?android:attr/listPreferredItemHeight"/>;

problem: the listView items only fit the text but NOT the whole screen?!?!?

like image 901
Erhard Dinhobl Avatar asked Dec 29 '10 09:12

Erhard Dinhobl


2 Answers

How are you creating your ListView? Is it defined in XML? Are you using a ListActivity? Or are you creating it programmatically? You need to make sure that the ListView itself has a width of fill_parent.

like image 73
Kevin Coppock Avatar answered Sep 25 '22 05:09

Kevin Coppock


Who is the parent view of your TextView? Check the settings for that one too, maybe it's a fixed width smaller than the screen or seted to "wrap_content" .

like image 45
Adinia Avatar answered Sep 25 '22 05:09

Adinia