0

I have a list view that is displaying the address information like city, state, zipcode. I want to add a text view header as the state changes.

So, is there any way to put a text view in between the data inside list view. enter link description here

srbyk1990
  • 411
  • 5
  • 17

2 Answers2

1

BaseAdapter has two functions that deal with having rows of different types:

getItemViewType(int position) and getViewTypeCount()

You can implement these as follows to do what you are looking for:

//Define constants for your different view types
public final int CONTACT_INFO_TYPE = 1;
public final int HEADER_TYPE = 2;

//Return which view type should be shown, based on the position in the list view
@Override
public int getItemViewType(int position) {
    if(something) {
        return HEADER_TYPE;
    } else {
        return CONTACT
}

//Return the count of different views shown in the list
@Override
public int getViewTypeCount() {
    return 2;
}

//Use getItemViewType(...) to decide what kind of View you should return
@Override
public View getView (int position, View convertView, ViewGroup parent) {
    int type = getItemViewType(position);
    if(type == CONTACT_INFO_TYPE) {
        //Return a view containing contact info
    } else {
        //Return a view containing header info
    }
}
Yjay
  • 2,717
  • 1
  • 18
  • 11
0

You're probably looking to use two different view types in your ListView. This post might be of some help.

Community
  • 1
  • 1
Submersed
  • 8,810
  • 2
  • 30
  • 38