Just in case anyone wants this in future, here is the solution to having a ListView with an addHeaderView enabled with a permanent TextView item at the top of list that doesn't move, even after you scroll through the list. If anyone has a better implementation please let me know as this doesn't extend ListActivity but just Activity. Cheers!
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textHeader" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Text Header, Always on Top"/> <ListView android:id="@+id/listEntries" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout> public class HelloListView extends Activity { private TextView th; private TextView tv; private ListView lv; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); th = (TextView) findViewById(R.id.textHeader); lv = (ListView) findViewById(R.id.listEntries); tv = new TextView(this); tv.setText("Hello There! Stays at top of list"); lv.addHeaderView(tv); lv.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, COUNTRIES)); lv.setOnItemClickListener(new ItemClickedListener()); } private class ItemClickedListener implements OnItemClickListener { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { String temp = arg0.getItemAtPosition(position).toString(); Toast.makeText(HelloListView.this, temp, Toast.LENGTH_SHORT).show (); } } static final String[] COUNTRIES = new String[] { "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina" }; } On 17 Aug, 16:33, Neil Chinniah <nchinn...@googlemail.com> wrote: > Just in case anyone is interested I found a thread in one of the other > groups that makes a reference to > HeaderViewListAdapter:http://groups.google.com/group/android-developers/browse_thread/threa... > > With this I created the following, its far from perfect but at least it > loads!!!! > > <?xml version="1.0" encoding="utf-8"?> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > > > <ListView > android:id="@+id/lvEntries" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > /> > </LinearLayout> > > public class HelloAddHeaderview extends Activity { > private ListView lv; > private TextView tv; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > lv = (ListView) findViewById(R.id.lvEntries); > tv = new TextView(this); > tv.setText("Hello There!"); > > lv.addHeaderView(tv); > > lv.setAdapter(new ArrayAdapter<String> > (this, android.R.layout.simple_list_item_1, COUNTRIES)); > } > > static final String[] COUNTRIES = new String[] { > "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", > "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", > "Argentina", > "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan" > }; > > } > > 2009/8/17 chinchin <nchinn...@googlemail.com> > > > Hello, > > I'm trying to modify the HelloListView example to use addHeaderView or > > addFooterView. Unfortunately I am unable to get this working. Is > > anyone able to provide any help? > > Here is my code, thanks in advance. > > > <?xml version="1.0" encoding="utf-8"?> > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > > android" > > android:orientation="vertical" > > android:layout_width="fill_parent" > > android:layout_height="fill_parent" > > > <TextView > > android:id="@+id/textDisplay" > > android:layout_width="fill_parent" > > android:layout_height="wrap_content" > > android:text="Hello!" > > /> > > </LinearLayout> > > > public class HelloListView extends ListActivity { > > private TextView test; > > > /** Called when the activity is first created. */ > > �...@override > > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > > > test = (TextView) findViewById(R.id.textDisplay); > > > getListView().addHeaderView(test); > > setListAdapter(new ArrayAdapter<String>(this, > > android.R.layout.simple_list_item_1, COUNTRIES)); > > getListView().setTextFilterEnabled(true); > > } > > > static final String[] COUNTRIES = new String[] { > > "Afghanistan", "Albania", "Algeria", "American Samoa", > > "Andorra", > > "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", > > "Argentina" > > }; > > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---