点按listview
项后,它应该将项ID 发送到另一个活动。
我的情况如下,它在
处显示错误Cursor cursor = trDb.getReminder(value);
,错误是
Incompatible type.
Required: android.database.Cursor;
Found: com.android.app.TRListFormat
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);
}
});
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
的 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));
}
答案 0 :(得分:1)
下面:
TRListFormat getReminder(int id)
getReminder
返回类型为TRListFormat
,但您尝试将TRListFormat
类对象分配给Cursor
对象:
TRListFormat objTRListFormat = trDb.getReminder(value);