首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android MatrixCursor

Android MatrixCursor
EN

Stack Overflow用户
提问于 2016-04-07 12:39:30
回答 1查看 370关注 0票数 0

我试图让一个基本的矩阵光标运行,但出于某种原因,列表仍然是空的。如果有人能发现代码可能有什么问题,会很感激吗?

代码语言:javascript
复制
    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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-08 08:52:10

未读取布局的原因是调用了不正确的布局:

代码语言:javascript
复制
        SimpleCursorAdapter(this,android.R.layout.list\_item,mc,s,r); Instead of:            SimpleCursorAdapter(this,R.layout.my\_list\_item,mc,s,r);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36476484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档