我需要在列表视图中显示数据库中的数据。我已经按类别分组获取了所有数据,并在Listview中显示。我使用了以下代码。
private ListView infos;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
.........
.........
infos = new ListView(this);
model = infoDataHelper.getCursor(addType);
adapter = new InfoAdapter(model);
infos.setAdapter(adapter);
.........
.........
}
class InfoAdapter extends CursorAdapter {
public InfoAdapter(Cursor c) {
super(getParent(), c);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View row, Context ctxt, Cursor c) {
InfoHolder holder = (InfoHolder) row.getTag();
holder.populateTable(c, infoDataHelper);
}
@Override
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.inforow, parent, false);
InfoHolder holder = new InfoHolder(row);
row.setTag(holder);
table_id++;
return (row);
}
}
现在我想在结果集中添加标题类别名称,使其看起来像这样 -
Categoty Fruit
Apple
Mango
Grape
Category Flower
Rose
Lotus
Jesmine
我该怎么做呢?使用addHeaderView可以实现吗?如果可以,我应该如何添加呢?