您好我正在尝试创建一个ListView
来实现StickyListHeadersListView
库并从Cursor获取数据。我在我的StickyListHeaderAdapter
中遇到了困难,我试图使用光标而不是string[]
。我正在寻找一些指南代码,但我看到的所有例子都使用字符串[]。
我的问题是
getCount()
中我说我需要一个整数而不是android.database.Cursor
还有其他方法来解决这个问题吗? setText(android.database.Cursor)
,我知道我必须在这里使用String[]
但是另外一种方法是什么? 这是我的代码
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;
}
}
非常感谢您的帮助!