public void onItemClick(AdapterView<?> a, View v, int position, long id) {
AlertDialog.Builder adb = new AlertDialog.Builder(CategoriesTab.this);
adb.setTitle("Selected Category");
adb.setMessage("Selected Item is = "+lv1.getItemAtPosition(position));
adb.setPositiveButton("Ok", null);
adb.show();
}
当点击listview中的项目时,此时会显示一个警告框。我想转换警报框以为每个单击的选项加载特定的xml。我怎样才能做到这一点? 谢谢你的帮助。
答案 0 :(得分:74)
switch(position) {
case 0:
setContentView(R.layout.xml0);
break;
case 1:
setContentView(R.layout.xml1);
break;
default:
setContentView(R.layout.default);
}
我希望这能做到这一点!
答案 1 :(得分:2)
switch(position) {
case 0:
...
break;
case 1:
...
break;
default:
...
}
你的意思是?
答案 2 :(得分:2)
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.:
break;
case R.id.:
break;
default:
break;
}
}
答案 3 :(得分:1)
你可以这样做:
@Override
protected Dialog onCreateDialog(int id) {
String messageDialog;
String valueOK;
String valueCancel;
String titleDialog;
switch (id) {
case id:
titleDialog = itemTitle;
messageDialog = itemDescription
valueOK = "OK";
return new AlertDialog.Builder(HomeView.this).setTitle(titleDialog).setPositiveButton(valueOK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(this.getClass().getName(), "AlertItem");
}
}).setMessage(messageDialog).create();
然后致电
showDialog(numbreOfItem);