从数据库中使用Android的GridView的数据显示 [英] show data in android using gridview from database
本文介绍了从数据库中使用Android的GridView的数据显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要显示的数据,从一个数据库,在GridView。
意味着我有一个数据在我的表(让它是一个客户的细节),我想表明它在GridView控件(或任何其他控件显示详细信息),如我们在asp.net做的一样。
解决方案: -
公共无效FillGrid(){
DatabaseHelper胸径=新DatabaseHelper(本);
dbh.openDataBase();
光标光标;
GridView控件GRV =(GridView控件)findViewById(R.id.grvData);
光标= dbh.getGridData();
dbh.close();
如果(指针!= NULL){
startManagingCursor(光标); SimpleCursorAdapter适配器=新SimpleCursorAdapter(这一点,
R.layout.gridlayout,光标,
新的String [] {GridTestActivity.KEY_ROW_ID,GridTestActivity.KEY_ID,GridTestActivity.KEY_DESCRIPTION}
,新的INT [] {R.id.txtGrv_id,R.id.txtGrvid,R.id.txtGrvDescription});
adapter.setViewResource(R.layout.gridlayout);
grv.setAdapter(适配器);
}}
解决方案
这里的的完整的例子的。
此外,如果你的Android开始这将是一个很好的书给你。
I want to display data, from a database, in a gridview. Means I have a data in my table (let it's a customer detail) and I want to show it in gridview (or any other control to display details) same as we done in asp.net.
Solution:--
public void FillGrid() {
DatabaseHelper dbh = new DatabaseHelper(this);
dbh.openDataBase();
Cursor cursor;
GridView grv = (GridView) findViewById(R.id.grvData);
cursor = dbh.getGridData();
dbh.close();
if (cursor != null) {
startManagingCursor(cursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.gridlayout, cursor,
new String[] { GridTestActivity.KEY_ROW_ID, GridTestActivity.KEY_ID, GridTestActivity.KEY_DESCRIPTION }
,new int[] { R.id.txtGrv_id, R.id.txtGrvid, R.id.txtGrvDescription } );
adapter.setViewResource(R.layout.gridlayout);
grv.setAdapter(adapter);
}
}
解决方案
Here's the full example.
Also if your beginning Android this would be a good book for you.
这篇关于从数据库中使用Android的GridView的数据显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文