【发布时间】:2011-03-11 05:41:42
【问题描述】:
按照我的代码将数据从数据库显示到列表视图。但它不会工作并使我的应用程序崩溃。请为我的这个问题提供完美的解决方案。
我的代码......
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.deletestudent);
// DisplayStudent();
ArrayList<String > arrlst=new ArrayList<String>();
ListView lst_stu=(ListView) findViewById(R.id.ListView01);
db.open();
Cursor cur=db.GetStudent();
for (int i=0;i<cur.getCount();i++)
{
cur.moveToFirst();
String stunm=cur.getString(1);
arrlst.add(1, stunm);
lst_stu.setAdapter((ListAdapter) arrlst);
db.close();
}
}
【问题讨论】:
-
为什么要在 for 循环中设置适配器并关闭数据库?
-
谢谢,现在我将更改我的代码。
标签: android sqlite android-listview