Android的分类的列表视图与标题 [英] Android Categorized listview with heading
问题描述
我不得不从在ListView数据库显示数据。我有categoty取组中的所有数据,并在列表视图中显示。我用下面的code。
I have to display data from the database in a listview. I have fetch all the data in group by categoty and displayed in a Listview. I have used the following code.
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名字的结果集,以便它看起来像 -
Now I want to add heading categoty name on result set so that it looks like that-
Categoty Fruit
Apple
Mango
Grape
Category Flower
Rose
Lotus
Jesmine
等..
我怎么做?是否addHeaderView工作呢?如果是,我如何能增加吗?
How can I make it? Does the addHeaderView work for it? If it is, How I can add it?
推荐答案
嘿,我也很久以前有同样的问题。经过一番google搜索,我发现这个教程的http://eshyu.word$p$pss.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/ 。它为我工作。
Hey i was also having the same problem long before. After much googling i found this tutorial http://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/ . It worked for me.
这篇关于Android的分类的列表视图与标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!