我正在处理一个应用程序,在OnItemclick
方法中,我使用了listview
的Switch语句,当我点击位置0时,它显示位置0项。当我在同一时间点击位置1时它没有响应。
这是代码:
list = (ListView) findViewById(R.id.list);
list.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, sims));
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Selectitem(position);
switch (position) {
case 0:
mapBeginConfigcities();
// mapBeginConfig();
loadUI();
mapEndConfig();
Toast.makeText(MainActivity.this, "0"+position,
Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(MainActivity.this, "1" + position,
Toast.LENGTH_SHORT).show();
mapBeginRoadsfill();
loadUI();
mapEndConfig();
Toast.makeText(MainActivity.this, "1" + position,
Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(MainActivity.this, "2" + position,
Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(MainActivity.this, "3" + position,
Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
public void Selectitem(int position) {
// TODO Auto-generated method stub
list.setItemChecked(position, true);
setTitle(sims[position]);
}
public void setTitle(String title) {
getSupportActionBar().setTitle(title);
}
});