2016-04-24 117 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不適用於應用程序 –