データベースの2 つの列をクエリし、単純なカーソル アダプターを使用してそれらを表示するためのメイン アクティビティにカーソルがあります。
private Cursor doQuery() {
return(db.getReadableDatabase().rawQuery("SELECT RestaurantID AS _id, RestaurantName, StoreNo "
+ "FROM RestaurantList ORDER BY RestaurantName", null));
}
public void onPostExecute() {
SimpleCursorAdapter adapter;
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {
adapter=new SimpleCursorAdapter(this, R.layout.activity_all_restaurants,
doQuery(), new String[] {
RestaurantDB.colRestaurantName,
RestaurantDB.colRestaurantStore },
new int[] { R.id.title, R.id.value },
0);
}
else {
adapter=new SimpleCursorAdapter(this, R.layout.activity_all_restaurants,
doQuery(), new String[] {
RestaurantDB.colRestaurantName,
RestaurantDB.colRestaurantStore },
new int[] { R.id.title, R.id.value });
}
setListAdapter(adapter);
}
私がやりたいことは、ユーザーが特定のアイテムをクリックすると、別のアクティビティがポップアップしてユーザーに詳細情報を提供することです。つまり、同じアイテムの他の多くの列に保存されているデータも表示する必要があります。私の質問は、どうすればそれができるかです。onListItemClick を使おうと思ったのですが、メインアクティビティで選択したアイテムを新しいアクティビティに関連付ける方法がわかりません。
また、メイン アクティビティでは、リストに 2 つのテキストビューがあり、それぞれ colRestaurantName と colRestaurantStore を表示します。onListItemClick を使用する場合、colRestaurantName を取得するにはどうすればよいですか?
次のようにして位置を取得できますが、新しいアクティビティでどのように使用できるかわかりません。
@Override
public void onListItemClick(ListView parent, View v, int position,
long id){
Cursor c = ((SimpleCursorAdapter)parent.getAdapter()).getCursor();
selection = String.valueOf(c.getPosition());
Intent i = new Intent(AllRestaurants.this, RestaurantsInfo.class);
i.putExtra("restaurantSelection", selection);
startActivity(i);
}
ありがとう。