我有一个按钮,当点击显示下拉列表时,我有2个菜单,反馈菜单和退出菜单
mRightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(MapsActivity.this, mRightButton);
popup.getMenuInflater()
.inflate(R.menu.nav_drawer, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_feedback) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder();
alertDialog.setTitle("Feedback");
alertDialog.setMessage("Beri kritik dan saran untuk aplikasi ini ?");
alertDialog.setIcon(R.drawable.ic_near_me_black_48dp);
alertDialog.setPositiveButton("YA", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] { "mrobbyf10@gmail.com" });
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
});
alertDialog.setNegativeButton("TIDAK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Bantu kami untuk meningkatkan kinerja dan performa aplikasi ini dengan memberi feedback",
Toast.LENGTH_LONG).show();
}
});
alertDialog.show();
我在AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
中输入“this”,但这是错误,我该怎么输入一些代码?
答案 0 :(得分:0)
而不是this
,请添加YourActivity.this
。
像
AlertDialog.Builder alertDialog = new AlertDialog.Builder(YourActivity.this);