私は、Androidでsqliteデータベースを使用することにまったく慣れていません。次のSQL文を使用してデータベースから値を取得したい:
"SELECT description FROM games WHERE _id =" + categoryID
ここで、categoryID は listView でクリックされた要素の位置です (_id 列の値でもあります)。
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
String categoryID = new Integer(position).toString();
final String SELECT_FROM = "SELECT description " + "FROM games "
+ "WHERE _id = " + categoryID;
database.query(SELECT_FROM);
Intent intent = new Intent();
intent.setClass(SqliteDbActivity.this, ViewAction.class);
Bundle b = new Bundle();
b.putString("categoryID", SELECT_FROM);
intent.putExtras(b);
startActivity(intent);
}
});
を使用する必要があることはわかっていますdatabase.query()
が、値を取得するには、前の SQL ステートメントをどのように正しく記述すればよいですか?
表は次のようになります。
_id description name
1 some1 name1
2 some2 name2
3 some3 name3
助けてください。