以下是我的代碼來顯示數據到數據庫的列表視圖。但它不會工作和崩潰我的application.please爲我的這個問題提供完美的解決方案。從SQLite填充Listview時,我的代碼出了什麼問題?
我的代碼......
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循環? – Abhinav 2011-03-11 05:46:24
現在,我要改變我的代碼。 – 2011-03-11 05:51:21