android - How to add more than one textView to listView -


i using custom adapter , have problem getview method. here code -

@override     public view getview(int position, view convertview, viewgroup parent) {         // todo auto-generated method stub         view vi = convertview;         if (vi == null)             vi = inflater.inflate(r.layout.list_item, null);      if(position==0){         textview text1 = (textview) vi.findviewbyid(r.id.text1);         text1.settext(data[position]);      }else if(position==1){         textview text2 = (textview) vi.findviewbyid(r.id.text2);         text2.settext(data[position]);       }         return vi;     } 

and here xml file -

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <textview     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:textalignment="center"     android:background="@android:color/black"     android:textcolor="@android:color/white"     android:id="@+id/text1" /> <textview     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:textalignment="center"     android:background="@android:color/green"     android:textcolor="@android:color/white"     android:id="@+id/text2" />   </linearlayout> 

actually if command working other blank textview appears it. suppose if position==0 "@+id/text1" should displayed, "@+id/text2" displayed no text. want 1 textview displayed, not other one. how that?

position index of displayed item in adapter, not textview being displayed.

each row of adapter has 2 textviews, , assume have string needs displayed in both views.

as example, try instead.

@override public view getview(int position, view convertview, viewgroup parent) {      string item = string.valueof(data[position]);      view v = convertview;     if (v == null) {         v = inflater.inflate(r.layout.list_item, null);     }      textview text1 = (textview) v.findviewbyid(r.id.text1);     textview text2 = (textview) v.findviewbyid(r.id.text2);      text1.settext("1: " + item);     text2.settext("2: " + item);      return v; } 

i want 1 textview displayed, not other one. how that?

then sounds don't want 2 textviews in 1 layout...

if question literally "how display more 1 textview in listview", should put more 1 value data array.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -