嗨,我已经搜索了与此相关的各种问题,但我无法解决问题。
我是 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