この問題で私を助けてくれることを願っています。リストビューで選択したアイテムのrowIdをsqliteから取得して、値を別のアクティビティに渡すことができるようにしたいと考えています。
私はすでにリストビューに自分のsqliteテーブルからの情報を入力し、リストビューでonClickedItemを使用し、pos + 1を使用してIDを取得していますが、リストビューからアイテムを削除するたびに正しいものを取得できないため、このソリューションは必要ありませんデータベース自体からのrowId...これは私のコードです:
私のDBhelperで:
public List<String> getSYAList() {
List<String> List = new ArrayList<String>();
try {
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_SYA ;
Cursor c = ourDatabase.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (c.moveToFirst()) {
do {
List.add((c.getString(0)) + " " +(c.getString(1)) + " "+ (c.getString(2)));
} while (c.moveToNext());
}
} catch (Exception e) {
Toast.makeText(ourContext, "Error encountered.",
Toast.LENGTH_LONG).show();
}
return List;
}
私の活動で:
private void loadSYA() { // TODO 自動生成メソッド スタブ
final DBhelper entry = new DBhelper(this);
entry.open();
final List<String> sya = entry.getSYAList();
if(sya.size()>0) // check if list contains items.
{
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(SYA.this,android.R.layout.simple_dropdown_item_1line, sya);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sqlSYA.setAdapter(arrayAdapter);
sqlSYA.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i = new Intent(SYA.this,SYAInfo.class);
Bundle b = new Bundle();
b.putInt("id", (int)position + 1);
i.putExtras(b);
startActivity(i);
}
}); }
else
{
Toast.makeText(SYA.this,"No items to display",1000).show();
}
entry.close();
}
誰かがこの問題の解決策を見つけるのを手伝ってくれることを本当に願っています. 事前に感謝します!!!