Filling data without using a list
I'm currently filling data in a layout with information in a database. I'm aware of list view but it doesn't seem to fit my purpose. I need to place queries into specific area's of a layout. Since all my information is under the same column in the database a list creates a separate row for each item. My current process requires 开发者_运维技巧a lot of code...
public void fillData(){
Cursor note = null;
note = mDbHelper.fetchItem(SaveSlot,"91");
startManagingCursor(note);
info_1.setText(note.getString(
note.getColumnIndexOrThrow((DbAdapter.VALUE1))));
note = mDbHelper.fetchItem(SaveSlot,"93");
startManagingCursor(note);
info_2.setText(note.getString(
note.getColumnIndexOrThrow((DbAdapter.VALUE1))));
note = mDbHelper.fetchItem(SaveSlot,"100");
startManagingCursor(note);
info_3.setText(note.getString(
note.getColumnIndexOrThrow((DbAdapter.VALUE1))));
}
My goal is to to fill a layout similar to a heads up display.
Is there a way to do this more efficiently? I've tried creating a array that contains all of the item numbers and textview names but couldn't figure out how to get it to work. Cant set text of an array. it was something like...
public void fillData(){
Cursor note = null;
for(int x =0; x<info.length;x++){
note = mDbHelper.fetchItem(SaveSlot,item[x]);
startManagingCursor(note);
info[x].setText(note.getString(
note.getColumnIndexOrThrow((DbAdapter.VALUE1))));
}
any thoughts?
edit:
My goal is to have multiple database queries per listview row
I'm not 100% certain about what you are looking for here, but from my understanding, try this:
Use
View.inflate(context, resourceId, null)
then cast the result to the layout referenced in resourceId.
Example:
(TextView)text = View.inflate(getApplicationContext(), R.layout.MyTextView, null);
linearLayout.addView(text);
Then, tie this behavior to iterating through the resultset from your database query. You will then build up your view based on the query results from your database.
精彩评论