Android MatrixCursor

时间:2016-04-07 12:39:30

标签: android matrixcursor

我正在尝试运行基本矩阵光标,但由于某种原因,列表仍为空。如果有人能够发现代码可能出现的问题,我将不胜感激?

    String []columns = new String[] {"_id","Title","Desc"} ;
    MatrixCursor mc = new MatrixCursor(columns);
    startManagingCursor(mc);

    for(int i=0; i< 200;i++)
    {
        mc.addRow(new Object[]{i, "test"+i ,"..."});
    }

    ListView lv = (ListView)findViewById(R.id.alist);

    int [] r = new int[1];
    r[0] = R.id.atext;           // the id of the textview in test_list_item layout
    String [] s= new String[1];  
    s[0] = mc.getColumnName(1);  // the column to be used "Title"
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.test_list_item,mc,s,r);

    lv.setAdapter(adapter);

1 个答案:

答案 0 :(得分:0)

未读取布局的原因是由于调用了错误的布局:
           SimpleCursorAdapter(此,android.R.layout.list_item,MC,S,R); 代替:            SimpleCursorAdapter(此,R.layout.my_list_item,MC,S,R);