2016-04-24 119 views
1
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(); 


        } 
       }); 

这是我的代码,用于删除一条警报,但警报不显示。正当我点击后退按钮显示所有警报。有任何想法吗?为什么alertdialog没有显示给我

它是被创造的onResume

@Override 
    public void onResume(){ 
    currentActivity=this; 
     super.onResume(); 
    } 
+0

on adapter .... –

+0

@YasirTahir你确定吗?我只看到alert.create(); 和我想我不能添加alret.build() –

+0

@MikeM。在我的adpter和onBindViewHolder ...在RecyclerView产品这里...和我的评论daynamicly创建 –

回答

0

呼叫alert.create()在MainActivity currentActivity显示()。

请参阅以下链接了解详情:https://stackoverflow.com/a/13511580/5460053

+1

@downvoter:请你解释downvote的原因如此我可以纠正自己。 –

+1

我不是downvoter,但我认为这是不好的做法,没有理由downvote。你会因为应该正常工作而降低投票率。如果您只使用构建器而不创建对话框,则show()就足够了。 – Opiatefuchs

+0

@Opiatefuchs:谢谢。你是对的。调用create()不是必需的。调用show()会立即创建并显示一个对话框。 –

1

只需使用这条线

AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext); 

代替

AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.currentActivity); 

我希望这会帮助你。

+0

你是对的,但我的Adpter不是活动的延伸......只是从baseAdaper –

+0

扩展而已。它从视角来看具有背景。 ''''public void onClick(View v){}'''v是在这里查看,我从它获得上下文。 –

+0

我试试看,并给我错误 无法添加窗口 - 令牌null不适用于应用程序 –