0
嗨我已經搜遍了與此相關的各種問題,但我無法解決問題。Android從Onitemclick數據庫獲取ID聆聽者
我是Android新手,我正在開發板球應用程序。在這裏,我顯示了一個來自數據庫的團隊,它包含TeamId和TeamName.TeamId是一個自動生成的值。當我點擊特定的團隊時,我想從數據庫中獲取所選的TeamId,並且我想通過此TeamID作爲捆綁來處理下一個功能。但我沒有從數據庫獲取團隊ID。
而下面就是我想到目前爲止代碼,
Intent intent = getIntent();
teamName=(ArrayList<String>)getIntent().getSerializableExtra("Teams");
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1,teamName);
teamList.setAdapter(adapter);
的ListView OnITEMCLICk
teamList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int id,long position) {
// TODO Auto-generated method stub
textOfSelectedItem =((TextView) v).getText().toString();
Log.v("Clicked item id", " "+ id);
Toast.makeText(getApplicationContext(), "Clicked is " + id, Toast.LENGTH_SHORT).show();
oncreated = false;
Intent intent=new Intent(TeamOneActivity.this,TeamPlayersTeamOne.class);
intent.putExtra("selected teamname", textOfSelectedItem);
startActivity(intent);
///g.setSelectedTeamOne(textOfSelectedItem);
}
});
這是我的數據庫
public ArrayList<String> getTeamID() {
// TODO Auto-generated method stub
ArrayList<String> TeamList=new ArrayList<String>();
String selectQuery="SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor=db.rawQuery(selectQuery, null);
if(cursor.moveToFirst())
{
do
{
//String TeamName=cursor.getString(cursor.getColumnIndex("TeamName"));
String TeamID=cursor.getString(cursor.getColumnIndex("TeamID"));
//TeamList.add(TeamName);
TeamList.add(TeamID);
}while(cursor.moveToNext());
cursor.close();
}
return TeamList;
}
任何一個可以幫助如何從數據庫獲取ID
非常感謝你......你的主意完美無缺..好邏輯.. – user1835052 2013-04-11 09:32:32
非常感謝@Cosmin Ionascu – 2014-11-28 06:08:43