How to merge StickyListHeadersListView and Cursor

311 views Asked by At

Hi I'm trying to make a ListView that implements StickyListHeadersListView library and gets the data from Cursor. I'm having difficulties in my StickyListHeaderAdapter where i'm trying to used cursor instead of string[]. I'm looking for some guideline codes but all examples i see are all using string[].

my problem are

  1. in the getCount() where it says i need an integer rather that android.database.Cursor is there any other way to get through this?
  2. Cannot resolve method setText(android.database.Cursor) , i know that i must use String[] in here but what are the other way to do this?

here is my code

public class StickyHeaderAdapter extends BaseAdapter implements StickyListHeadersAdapter {

private Cursor information, header;
private LayoutInflater inflater;
DBHelper dbHelper;

public StickyHeaderAdapter(Context context, Cursor countries, Cursor header) {
    inflater = LayoutInflater.from(context);
    countries = dbHelper.getInformationItems();
    header = dbHelper.getInformationHeader();
}

@Override
public int getCount() {
    return information;
}

@Override
public Object getItem(int position) {
    return information;
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.text_list_item_layout, parent, false);
        holder.text = (TextView) convertView.findViewById(R.id.list_title);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.text.setText(information );
    return convertView;
}

@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
    HeaderViewHolder holder;
    if (convertView == null) {
        holder = new HeaderViewHolder();
        convertView = inflater.inflate(R.layout.header, parent, false);
        holder.text = (TextView) convertView.findViewById(R.id.header);
        convertView.setTag(holder);
    } else {
        holder = (HeaderViewHolder) convertView.getTag();
    }


    holder.text.setText(header);
    return convertView;
}

@Override
public long getHeaderId(int position) {
    return position;
}

class HeaderViewHolder {
    TextView text;
}

class ViewHolder {
    TextView text;
 }

}

Thank you so much for the help!

0

There are 0 answers