我要控制在此點擊對話框的事件有三個項目如何控制點擊事件的對話框中的Android
當我點擊牛奶..Other功能Perform..when我點擊黃油等功能進行 我想知道如何控制項目選擇
這是我的對話框的代碼框中
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
// TODO Auto-generated method stub
UserModel user = (UserModel)getActivity(). getIntent().getSerializableExtra("User");
String User_id= contactList.get(position).get("User_Id");
String Request_id=contactList.get(position).get("Request_Id");
String Accpeter_Id=String.valueOf(user.getUser_Id());
//List items
final CharSequence[]items = {"Milk", "Butter", "Cheese"};
//Prepare the list dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//Set its title
builder.setTitle("Request Confirmation");
//Set the list items and assign with the click listener
builder.setItems(items, new DialogInterface.OnClickListener() {
// Click listener
public void onClick(DialogInterface dialog, int item) {
//Toast.makeText(getActivity(), items[item], Toast.LENGTH_SHORT).show();
if(items.equals(items[item])){
Toast.makeText(getActivity(), "Hi friends CLicked", Toast.LENGTH_SHORT).show();
}
else if(items.equals(items[item])){
Toast.makeText(getActivity(), "hi butter Mutter", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getActivity(), "Cheesy way hehehe", Toast.LENGTH_SHORT).show();
}
}
});
AlertDialog alert = builder.create();
//display dialog box
alert.show();
}
當我點擊任何其他項塊的任何點擊打印
我設置條件像這樣
if(items.equals(items[item])){
Toast.makeText(getActivity(), "Hi friends CLicked", Toast.LENGTH_SHORT).show();
}else if(items.equals(items[item])){
Toast.makeText(getActivity(), "hi butter Mutter", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getActivity(), "Cheesy way hehehe", Toast.LENGTH_SHORT).show();
}
只有else條件顯示任何項目點擊 Telll我I m什麼做錯了,whare ...
thanku
我發現這裏的解決方案: http://stackoverflow.com/questions/4113939/handling-buttons-in-custom-dialogs/4114017#4114017 它工作在我的情況。 – 2014-09-02 07:39:25