I’m using a database that is implemented in a ListView.
I want to section the ListView and add headers (separators). What I mean is, that I have many cities, and I want to group them by country with seperators.
Here is the class, which I think, has something to do with headers:
String[] adobe_products = getResources().getStringArray(R.array.adobe_products);
mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products);
// Binding Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/* // selected item
String product = ((TextView) view).getText().toString();
// Launching new Activity on selecting single List Item
Intent i = new Intent(getApplicationContext(), SingleListItem.class);
// sending data to new activity
i.putExtra("product", product);
startActivity(i);*/
A separator is basically a just a custom list item. You need to override the adapter to return a disabled list item where you want the headers to be.
For your instance, you could add the separators in the string arrays at the right position and make the following adjustments to a custom adapter:
Then one way of doing it is to have a separate list of only the header items then creating a method like this to check the item type for all the methods mentioned above.