I want that as I click on list item the application should load another class and then display the required data on textview by retrieving the data from sqlite database
@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);
}
this code is in WordDetails class
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")));
}
}
When I click on an item “Error” word is being displayed which is supposed to show, but wordTd equals -1. Why this wordId is not getting correct value? Thanks for your help.
The ‘keys’ used when putting
Intentextras are case sensitive. You are putting the id as……but then trying to get it with…
In other words you’re putting
Word_IDand trying to getWORD_ID. Change the code so they’re both the same and it should work.