点击菜单我要打开警报拨号框
实际上错误是来自视图充气器...... 我不知道在菜单部分中要充气什么 menuinflator中的 inflate(int,menu)我不知道在菜单下填充什么
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.add_to_playlist:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view1 = inflater.inflate(R.layout.alert_textview_inflator);
builder.setView(view1);
final EditText play_list_name = (EditText) view1.findViewById(R.id.alertTextEditor);
builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Editable m = play_list_name.getText();
String folder_name_act = m.toString();
// addComment(folder_name_act);
}
});
builder.setNegativeButton("Cancil", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
break;
case R.id.delete:
Log.e("qwerty", "delete");
break;
}
return true;
}
});
popup.show();
}
});
答案 0 :(得分:0)
试试这个
View view = getLayoutInflater().inflate(R.layout.alert_textview_inflator, null, false);
答案 1 :(得分:0)
我稍微更改了您的代码。试试这个可以帮助你
private void showPopUpMenu(View view){
PopupMenu popupMenu = new PopupMenu(mContext, view);
popupMenu.getMenuInflater().inflate(R.menu.menu_popup, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.add_to_playlist:
showAlert();
break;
case R.id.delete:
Log.e("qwerty", "delete");
break;
}
return false;
}
});
popupMenu.show();
}
private void showAlert(){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view1 = inflater.inflate(R.layout.alert_textview_inflator, null, false););
builder.setView(view1);
final EditText play_list_name = (EditText) view1.findViewById(R.id.alertTextEditor);
builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Editable m = play_list_name.getText();
String folder_name_act = m.toString();
// addComment(folder_name_act);
}
});
builder.setNegativeButton("Cancil", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}