android - Adding A button and a TextView for each Line of a ListView -


i working on basic android application , have encountered obstacle cannot solve on own.

in application want have start screen listview. in each line of listview there should button , textview. want have approximately 5 lines. when click on each of button should able different activities. how do that? read adapters still not sure how build this.

here's xml code textview , button:

<relativelayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/textview"     android:id="@+id/rl01">     <textview         android:layout_width= "wrap_content"         android:layout_height="50dp"         android:id="@+id/text01"         android:text="hello"         android:textsize="24dp"         android:textcolor="@color/abc_search_url_text_normal"         android:paddingright="@dimen/activity_horizontal_margin"          />     <button         android:layout_width="wrap_content"         android:layout_height="50dp"         android:layout_torightof="@id/text01"         android:text="press me!"         /> </relativelayout> 

the xml layout have posted, used each listview item.

step 1: create class extends baseadapter;

public class customadapter extends baseadapter {     context con;     string[] data;     public  customadapter (context context, string[] data)     {         this.con = context;          this.data = data;      }     @override     public int getcount() {         return data.length;     }      @override     public object getitem(int position) {         return data[position];     }      @override     public long getitemid(int position) {         return 0;     } //this method called every item of listview     @override     public view getview(int position, view convertview, viewgroup parent) {         layoutinflater inflater = (layoutinflater) con.getsystemservice(context.layout_inflater_service);         convertview= inflater.inflate(r.layout.customview, parent, false);         textview text = (textview) view.findviewbyid(your text view id); //recognize view       text.settext(data[position]);         return convertview;  }  } 

step 2: in activity, recognize listview:

yourlistviewreference = (listview) findviewbyid(r.id.your_list_view_id); 

and initialize string array:

string[] data = {"item 1", "item2", "item3"}; //how many items want 

and create instance of custom adapter created, , set listview:

customadapter ad = new customadapter(this, data); yourlistviewreference.setadapter(ad); 

and sorry bad english. working on it.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -