我想在gridview中显示数据库中的数据.
意味着我的表中有数据(让它成为客户详细信息),我想在gridview(或任何其他控件中显示详细信息)中显示它,就像在asp.net中一样.
解: –
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);
}
}
解决方法:
此外,如果你开始Android this对你来说是一本好书.
标签:android,android-widget,gridview
来源: https://codeday.me/bug/20190630/1337424.html