Java 如何从SQLite添加到列表中
我的应用程序将接收短信,保存在SQLite中,然后显示在我的列表中。 其余的都完成了,但我无法将数据放入我的列表中;我该怎么做 以下是我正在尝试的:Java 如何从SQLite添加到列表中,java,android,sqlite,list,Java,Android,Sqlite,List,我的应用程序将接收短信,保存在SQLite中,然后显示在我的列表中。 其余的都完成了,但我无法将数据放入我的列表中;我该怎么做 以下是我正在尝试的: list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View view, int position, long index) {
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view,
int position, long index) {
// here send Recent case Object OR or Recent case info. to show case information
}
});
我还是不太清楚你在问什么,所以我不知道这是否有帮助。我想你大概要做以下几点: 1) 通过查询要放入列表中的数据,创建一个android.database.Cursor对象 2) 使用查询中要显示的列创建字符串数组。例如,
String[]from_list=新字符串[]{“title”,“case”}
3) 使用要填写的列表行中文本视图的ID创建一个int数组。例如,int[]to_list=newint[]{R.id.title,R.id.case}
4) 创建SimpleCursorAdapter以将光标映射到列表:
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter (this, R.layout.list_row, mCursor, from_list, to_list);
5) `setListAdapter(mAdapter)
这有帮助吗?您是否试图理解如何将数据从SQLite表中获取到ListView中?我不清楚你在哪方面有问题。您是否尝试过使用SimpleCursorAdapter?您需要使用适配器才能将数据绑定到ListView。@happydave请检查我的update@ShashankKadne你能检查一下我的编辑吗?我做了所有的数据库、适配器和bla-bla,但是现在我的列表有baseadapter,数据库有cursor,问题是:如何向用户显示baseadapter中的信息,请检查我的代码好吗??我都做了,我想我的问题真的很小,但我不能得到它
public static List<RecentCaseClass> RecentCaseList = new ArrayList<RecentCaseClass>();
public static List<RecentCaseClass> getRecentCaseList() {
return RecentCaseList;
}
public static void setRecentCaseList(List<RecentCaseClass> recentCaseList) {
RecentCaseList = recentCaseList;
}
if (SMSReceived.startsWith("Hi")) {
Toast.makeText(context, "Iam in hi", Toast.LENGTH_LONG)
.show();
msg = SMSReceived;
RecentCaseClass rCase = run();
dbAdapter.add(rCase);
All_Static.RecentCaseList.add(recent1);
}
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter (this, R.layout.list_row, mCursor, from_list, to_list);