在我的Android应用程序,我有一个正常的少数listview使用String []
,但我有一个从SQLite数据库的列表视图。它表明它很好,这不是问题。此问题已记录我按它的选择,因为它只是似乎登录[email protected]????
,当我使用举杯显示字符串从SQLite填充列表视图中的选择作为字符串
我不得不代码做什么,我想用选项名称
做所以如果有人能够帮助我将选项名称存储在一个字符串中并用于烤面包,这将非常有帮助...因为这是我测试代码的方式。由于
我发布,填补下方如果使用列表视图SQLite的值
final ListView list = (ListView) findViewById(R.id.listView1);
@SuppressWarnings("deprecation")
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, //context
android.R.layout.simple_list_item_1, db.getValues(), //Cursor
new String[] {"SocietyName"}, new int[] {
android.R.id.text1
});
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
String favname = (String)((Cursor) list).getString(position);
Toast.makeText(getApplicationContext(), favname, Toast.LENGTH_SHORT).show();
}
});
MyDBAdapter.java帮助
FavouritesScreen.java ... ListView控件的代码......得到的值从SQLite数据库
public Cursor getValues() {
if (!isOpen()) {
open();
}
System.out.println("3a");
Cursor mCursor = db.query(true, "Favourites", // table name
new String[] {
"_id", "SocietyName"
}, // select clause
null, // where clause
null, // where clause parameters
null, // group by
null, // having
null, // order by
null); // limit
System.out.println("4a");
return mCursor;
}
非常感谢'columnIndex'与什么关系? – user2291530
游标包含尽可能多的列,你使用'new String [] {“_id”,“SocietyName”}'。如果你想使用'getString(1)'显示''SocietyName'''数据,所以'columnIndex'是你的String Array中列的索引。 – Sam
完美,非常感谢:) – user2291530