android - How to display each element of an array in different textviews in an arraylist -
i creating android application. have array shown below:
array: {item1, item2, item3, item4, item5, item6, item7, item8, item9, item10.........}; i want display these items in list view. structure of list view should shown below:
row1: item1 item2 item3 item4 item5 row2: item6 item7 item8 item9 item10 row3: item11 .... .... ..... ...... etc i have tried using array adapter , base adapter. every item getting list view shown below:
item1 item2 item3 item4 item5 item6 item7 item8 .... the code have tried shown below:
using array adapter:
string array searchdata
arrayadapter arrayadapter = new arrayadapter(getapplicationcontext(), r.layout.custom_search_row, r.id.textview3, searchdata); mlistview.setadapter(arrayadapter); using base adapter:
class singlerow { string mfetcheddata1; // string mfetcheddata2; // string mfetcheddata3; // string mfetcheddata4; // string mfetcheddata5; singlerow(string mfetcheddata1){ this.mfetcheddata1 = mfetcheddata1; // this.mfetcheddata2 = mfetcheddata2; // this.mfetcheddata3 = mfetcheddata3; // this.mfetcheddata4 = mfetcheddata4; // this.mfetcheddata5 = mfetcheddata5; } } class myadapter extends baseadapter { arraylist<singlerow> list; context context; myadapter(context c){ context = c; list = new arraylist<singlerow>(); string[] mfetcheddata = searchdata; (int i=0; i<4; i++){ list.add(new singlerow(mfetcheddata[i])); } } @override public int getcount() { return list.size(); } @override public object getitem(int position) { return list.get(position); } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view row = inflater.inflate(r.layout.custom_search_row, parent, false); textview title = (textview) row.findviewbyid(r.id.textview3); singlerow temp = list.get(position); title.settext(temp.mfetcheddata1); return row; } } mlistview.setadapter(new myadapter(getapplicationcontext())); my single row of list view shown below:
custom_row.xml:
<?xml version="1.0" encoding="utf-8"?> <horizontalscrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="small text" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/colorprimary" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancesmall" android:text="small text" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:id="@+id/textview4" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancesmall" android:text="small text" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:id="@+id/textview5" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancesmall" android:text="small text" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:id="@+id/textview6" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancesmall" android:text="small text" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:id="@+id/textview7" /> </linearlayout> </horizontalscrollview> if 1 have idea please me. suggestions welcome. if need information please let me know.
try using gridlayout custom colums option. change listview , adapter gridview.
Comments
Post a Comment