2011-03-15 236 views
0

我目前正在用数据库中的信息填充数据。我知道列表视图,但它似乎不符合我的目的。我需要将查询放入布局的特定区域。由于我的所有信息都位于数据库的同一列中,因此列表会为每个项目创建一个单独的行。我目前的过程需要大量的代码......不使用列表填充数据

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)))); 

} 

我的目标是,以填补类似于平视显示器的布局。

有没有办法更有效地做到这一点?我试过创建一个包含所有项目编号和textview名称的数组,但无法弄清楚如何让它工作。不能设置数组的文本。它是这样的...

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)))); 
} 

有什么想法?

编辑:

我的目标是让每个列表视图行多个数据库查询

回答

0

我不是100%肯定你在这里找什么,但是从我的理解,试试这个:

使用

View.inflate(context, resourceId, null) 

然后把结果向RESOURCEID引用的布局。

例子:

(TextView)text = View.inflate(getApplicationContext(), R.layout.MyTextView, null); 
linearLayout.addView(text); 

然后,配合这种行为通过从数据库查询结果集来迭代。 然后,您将根据数据库的查询结果构建视图。

+0

是否有可能使用info [x]而不是R.layout.MyTextView其中info []将是包含每个视图的id的字符串数组?我认为类型int不是字符串将是必需的。 – Wayner 2011-03-16 10:44:45