如何在Android中使用SimpleCursor Adapter获取ListView中的2列?

时间:2016-12-04 12:17:33

标签: android listview

我正在使用SimpleCursorAdapter使用一列填充我的列表视图,但我必须更改它并使用 2列填充我的列表视图。

现在我的代码看起来像这样:

SimpleCursorAdapter SimpleCursorAdapter;
ListView listWords = (ListView) findViewById(R.id.listWords);
wordsRepo wordsRepo = new wordsRepo(this);
TextView textview= (TextView) findViewById(R.id.textView);

private void showWords()
{
    Cursor cursor = wordsRepo.getword();

    if (cursor == null)
    {
        textview.setText("Error");
        return;
    }
    if (cursor.getCount() == 0)
    {
        textview.setText("No Words.");
        return;
    }

    String[] from = new String[] {word.KEY_EN_NAME};
    int[] to = new int[] {android.R.id.text1};

    SimpleCursorAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,from,to,0);
    listCategories.setAdapter(SimpleCursorAdapter);
}

listview只显示word.KEY_EN_NAME的值,但现在我要显示2列:word.KEY_EN_NAMEword.KEY_ES_NAME

有什么想法吗?谢谢你的帮助。

0 个答案:

没有答案