Android: Adding header to dynamic listView -
i'm still pretty new android coding, , trying figure things out. i'm creating listview dynamically shown below (and disabling items dynamically also) - you'll notice there's no xml file activity itself, listitem.
what i'd add static header page. explain me how can modify code below either add programatically within java file, before listview, or edit code below targets listview within xml file!
help appreciated!!!
public class start extends listactivity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); databasehelper mydbhelper = new databasehelper(null); mydbhelper = new databasehelper(this); try { mydbhelper.opendatabase(); }catch(sqlexception sqle){ throw sqle; } arraylist<string> categorylist = new arraylist<string>(); cursor cur = mydbhelper.getallcategories(); cur.movetofirst(); while (cur.isafterlast() == false) { if (!categorylist.contains(cur.getstring(1))) { categorylist.add(cur.getstring(1)); } cur.movetonext(); } cur.close(); collections.sort(categorylist); setlistadapter(new arrayadapter<string>(this, r.layout.listitem, categorylist) { @override public view getview(int position, view convertview, viewgroup parent) { view view = super.getview(position, convertview, parent); if(arrays.aslist(checkarray3).contains(string.valueof(position))){ view.setenabled(false); } else { view.setenabled(true); } return view; } }); } @override protected void onlistitemclick(listview l, view v, int position, long id) { if(v.isenabled()) { string clickedcat = l.getitematposition(position).tostring(); toast.maketext(this, clickedcat, toast.length_short).show(); finish(); intent myintent = new intent(getapplicationcontext(), questions.class); myintent.putextra("passedcategory", clickedcat); myintent.putextra("starttrigger", "go"); startactivity(myintent); } } }
you need create additional xml file activity display list. might this:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:scaletype="fitxy" android:src="@drawable/view"/> <linearlayout android:id="@+id/linearlayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <imageview android:id="@+id/homelogo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaletype="fitstart" android:src="@drawable/logo" /> </linearlayout> <listview android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/linearlayout1" android:layout_centerhorizontal="true" android:cachecolorhint="#00000000"> </listview> </relativelayout>
what have xml layout activity displays listview, , in there can add static header. did same thing app i'm building. there reference xml in activity using. hope helps.
Comments
Post a Comment