私のアプリの目的は、SQLite データベースから取得したモジュールのリストを表示することです。ユーザーが特定のモジュールをクリックすると、新しいアクティビティが開始され、その特定のモジュールに関連するデータベース内に保存された詳細情報が提供されます。
私が望んでいたのは、行 ID を取得してインテントで送信することでしたが、行 ID をカーソル アダプターから onClickListItem に取得する方法がわかりません。どんな提案でも大歓迎です。
カーソルアダプタ
public class TestCursorAdapter extends CursorAdapter {
private LayoutInflater viewInflater;
public TestCursorAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
// TODO Auto-generated constructor stub
viewInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public void bindView(View v, Context context, Cursor c)
{
TextView text_modulecode = (TextView)v.findViewById(R.id.labelModuleCode);
TextView text_modulename = (TextView)v.findViewById(R.id.labelModuleName);
text_modulecode.setText(c.getString(c.getColumnIndex(database.KEY_MODULECODE)));
text_modulename.setText(c.getString(c.getColumnIndex(database.KEY_MODULENAME)));
String moduleId = c.getString(c.getColumnIndex(database.KEY_ROWID));
}
@Override
public View newView(Context context, Cursor c, ViewGroup parent) {
View v = viewInflater.inflate(R.layout.listcourses, parent, false);
return v;
}
}
主な活動から
public void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this,ViewCourse.class);
//---> <--
intent.putExtra(TEST,moduleId);
startActivity(intent);
}