android - Setting title for listview -
i have android app should parse data php web page , display them 2 listview, each listview display values of string
my problem how set titles these listviews?
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); new getdata().execute(); } private class getdata extends asynctask<void, void, void> { progressdialog progressdialog; string data; list<string> r = new arraylist<string>(); list<string> r2 = new arraylist<string>(); arrayadapter<string>adapter=new arrayadapter<string>(getapplicationcontext(), android.r.layout.simple_list_item_1,r); arrayadapter<string>adapter2=new arrayadapter<string>(getapplicationcontext(), android.r.layout.simple_list_item_1,r2); listview list = (listview)findviewbyid(r.id.right); listview list2= (listview)findviewbyid(r.id.left); public getdata() { } @override protected void onpreexecute() { super.onpreexecute(); list.setbackgroundcolor(color.background_dark); list2.setbackgroundcolor(color.background_dark); progressdialog = new progressdialog(mainactivity.this); progressdialog.setcancelable(false); if (!progressdialog.isshowing()) { progressdialog.show(); } } @override protected void doinbackground(void... params) { try { defaulthttpclient client = new defaulthttpclient(); httpget request = new httpget("http://192.168.1.97:89/derdeery/zaki.php"); httpresponse response = client.execute(request); httpentity entity=response.getentity(); data=entityutils.tostring(entity); jsonarray json=new jsonarray(data); log.e("string", data); } catch(exception e) {} return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); try { if (progressdialog.isshowing()) { progressdialog.dismiss(); } jsonarray json=new jsonarray(data); for(int i=0;i<json.length(); i++) { string name=obj.getstring("part_name"); string id = obj.getstring("part_id") ; log.e("name", name); r.add(id ); r2.add(name); } list.setadapter(adapter); list2.setadapter(adapter2); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } }} }
activity_main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <listview android:id="@+id/left" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_weight="0.52"/> <listview android:id="@+id/right" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_weight=".25" /> </linearlayout>
you can create textview , add header view of listview
textview titletext = new textview(this); titletext.settext("title listview 1"); listview.addheaderview(titletext);
Comments
Post a Comment