【问题标题】:Using a ListAdapter to show database data使用 ListAdapter 显示数据库数据
【发布时间】:2010-06-22 06:13:50
【问题描述】:
public class List_View extends ListActivity {

    private TextView toptext; 
    private TextView bottomtext;

    DBAdapter db = new DBAdapter(this);

    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.list);
        getData();

        toptext = (TextView) findViewById(R.id.toptext); 
        bottomtext = (TextView) findViewById(R.id.bottomtext); 

    }

    private void getData() {            
           db.open();

           Cursor c = db.getAllEntry();
           c.moveToFirst(); 

           ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.view_list, c, new String[] {"date", "title"}, new int[] {R.id.toptext, R.id.bottomtext});

           bottomtext.setText(c.getString(1)); 
           toptext.setText(c.getString(4)); 

           setListAdapter(adapter);

           db.close(); 
    }

}

我想将存储的数据从数据库显示到 ListView。

仅限标题和日期。

【问题讨论】:

  • 请考虑花点时间看看这里的其他问题。没有一个都是大写的,或者需要“帮助”这个词——它是一个问答网站,因此“帮助”是多余的。此外,使用“URGENT :(”之类的短语不会帮助您更快地获得帮助
  • ... 然后,请告诉我们您的问题到底是什么。您似乎已经有一段代码,不幸的是它不起作用。因此,请解释代码试图做什么以及实际结果是什么。顺便说一句:这里的问题几乎总是很快得到回答,如果您花时间制定您的问题,以便读者立即理解。
  • 因为我真的非常渴望得到答案。 &问题是我似乎无法在我想要的列表视图中显示来自数据库的数据!
  • [将存储的数据从我的数据库中获取到 ListView 中的可能重复项。 ](stackoverflow.com/questions/3090041/…)

标签: android database listview


【解决方案1】:

只是扫了一眼;您对 getData 的调用位于设置 toptext 和 bottomtext 之前。

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2015-12-31
    • 2013-12-21
    • 2018-03-17
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多