首先,假設你使用擴展ArrayAdapter與美國,像一個適配器類:
public class StatesItemAdapter extends ArrayAdapter<UsState>
然後你有一個像ArrayList的列表作爲一個ArrayAdapter正確的數據源?然後,
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
UsState state = statesList.get(position); // on ArrayList
// or try statesList.get(listView.getSelectedItemPosition());
Intent citiesIntent = new Intent(getApplicationContext(), CitiesActivity.class);
citiesIntent.putExtra("state_name", state.getName()); // Name string originating from database record
startActivity(citiesIntent);
}
然後在城市活動,在的onCreate你必須得到國家的名字,並把它作爲你的數據庫查詢條件來獲得城市結果的光標:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle bundleExtras = intent.getExtras();
String selectedState = bundleExtras.getString("state_name");
// Do database query on cities relating to state
.......
我得到的錯誤多個標記在該行 \t - 令牌「(」語法錯誤;預計 \t - 虛空是一個無效的類型變量 \t onItemClick \t - 語法令牌錯誤「」;預期 \t - 令牌上的語法錯誤「,」,;預期 \t - 令牌上的語法錯誤「,」,;預期 \t - 令牌上的語法錯誤「)」,;預計在代碼中:_italic_public void onItemClick(AdapterView > arg0,View v,int position,long id){_ italic_ – user963070 2012-03-25 20:00:28
我不明白的必要性:public class StatesItemAdapter extends ArrayAdapter –
user963070
2012-03-25 20:03:17