remove_comment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.currentActivity);
alert.setTitle("are you sure?");
alert.setCancelable(true);
alert.setPositiveButton("yeah", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
RequestParams params = new RequestParams();
params.put("comment_id", item.getComment_id());
Internet.post("event/remove_comment", params, "removed");
base.setVisibility(View.GONE);
myevent.get(position).commenter.remove(holder.mpoid);
notifyDataSetChanged();
}
});
alert.setNegativeButton("no", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alert.show();
}
});
这是我使用提醒删除一条评论的代码,但警报未显示。就在我点击后退按钮显示所有警报时。有任何想法吗?
在onResume
上创建的MainActivity上的currentActivity @Override
public void onResume(){
currentActivity=this;
super.onResume();
}
答案 0 :(得分:1)
只需使用此行
即可 AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext);
而不是
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.currentActivity);
我希望这会对你有所帮助。
答案 1 :(得分:0)
调用alert.create()。show();
有关详细信息,请参阅此链接:https://stackoverflow.com/a/13511580/5460053