我希望当我单击列表项时,应用程序应该加载另一个类,然后通过从 sqlite 数据库中检索数据来在 textview 上显示所需的数据
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Intent intent = new Intent(DictionaryActivity.this,
WordDetails.class);
// Cursor cursor = (Cursor) adapter.getItem(position);
id = wordList.getItemIdAtPosition(position);
intent.putExtra("Word_ID", id);
// cursor.getInt(cursor.getColumnIndex("_id"));
startActivity(intent);
}
此代码在 WordDetails 类中
wordId = getIntent().getIntExtra("WORD_ID", -1);
if (wordId == -1) {
mean = (TextView) findViewById(R.id.mean);
mean.setText("Error");
} else {
SQLiteDatabase db = (new DatabaseHelper(this))
.getReadableDatabase();
Cursor cursor = db.rawQuery(
"SELECT _id ,word, mean FROM Meanings WHERE _id = ?",
new String[] { "" + wordId });
if (cursor.getCount() == 1) {
cursor.moveToFirst();
mean = (TextView) findViewById(R.id.mean);
mean.setText(cursor.getString(cursor.getColumnIndex("mean")));
}
}
当我点击一个项目“错误”字被显示,它应该显示,但wordTd
等于-1。为什么这wordId
没有得到正确的价值?谢谢你的帮助。