When listview
item is tapped it should send the item id to the another activity.
My is as follows, it shows an error at
Cursor cursor = trDb.getReminder(value);
and the error is
Incompatible type.
Required: android.database.Cursor;
Found: com.android.app.TRListFormat
code snippet of TRList.class
lv = (ListView)findViewById(R.id.tbr_list);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(TRList.this, TRTimeReminder.class);
intent.putExtra("remId", (int)id);
startActivity(intent);
}
});
code snippet of TRTimeReminder.class
Bundle extras = getIntent().getExtras();
if(extras != null){
int value = extras.getInt("remId");
if(value > 0){
Cursor cursor = trDb.getReminder(value); //this line is red showing the error I have written above
id_To_Update = value;
cursor.moveToFirst();
String title = cursor.getString(cursor.getColumnIndex(TRDBHelper.COLUMN_TITLE));
String des = cursor.getString(cursor.getColumnIndex(TRDBHelper.COLUMN_DES));
String date = cursor.getString(cursor.getColumnIndex(TRDBHelper.COLUMN_DATE));
String time = cursor.getString(cursor.getColumnIndex(TRDBHelper.COLUMN_TIME));
if (!cursor.isClosed()) cursor.close();
edTitle.setText(title);
edDes.setText(des);
dateView.setText(date);
timeView.setText(time);
}
}
getReminder
method of TRDBHelper.class
TRListFormat getReminder(int id){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_ID, COLUMN_TITLE, COLUMN_DES,
COLUMN_DATE, COLUMN_TIME}, COLUMN_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);
if(cursor != null){
cursor.moveToFirst();
}
return new TRListFormat(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
}
Aucun commentaire:
Enregistrer un commentaire