我从变量缓冲区的数据库获取数据,我希望这些数据显示在ListView
这是我的adaper
private void setAdapterData() {
DBHelper db = new DBHelper(this);
for (students stud : CustomListViewValuesArr) {
db.insertContact(stud.getrollno(), stud.getfirst(), stud.getsecond(), stud.getper());
}
Log.d("Reading: ", "Reading all contacts..");
ArrayList<students> stu = db.getAllCotacts();
res = getResources();
adapter = new CustomAdapter(CustomListView, stu, res);
studentlist.setAdapter((ListAdapter) adapter);
}
答案 0 :(得分:0)
我完成了,
使用Cursor
将此活动的意图发送到另一个活动Cursor c = db.rawQuery(&#34; SELECT * FROM student&#34;,null);
if (c.getCount() == 0) {
showMessage("No records found");
return;
}
// convert array list to string
List<String> buffer = new ArrayList<String>();
while (c.moveToNext())
{
buffer.add("" + c.getString(1)+ " "+ c.getString(2));
}
Intent intent = new Intent(this, viewdetails.class);
intent.putStringArrayListExtra(EXTRA_MESSAGE, (ArrayList<String>) buffer);
startActivity(intent);
}
在另一个列表活动中
Intent intent=getIntent();
ArrayList<String> buffer = intent.getStringArrayListExtra(MainActivity.EXTRA_MESSAGE);
ListView lListView = new ListView(this);
lListView = (ListView)findViewById(R.id.content);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,buffer);
lListView.setAdapter(adapter);