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();


                    }
                });

This is my code for removing one comment with alert, but The alert does not show. Just when I click on back button show all alert. Any ideas?

It is currentActivity on MainActivity that was created onResume

   @Override
    public void onResume(){
   currentActivity=this;
        super.onResume();
    }
JSON C11
  • 10,137
  • 6
  • 75
  • 63
gh darvishani
  • 41
  • 1
  • 11

2 Answers2

1

Just use this line

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

instead of

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

I hope this will help you.

Zeeshan Shabbir
  • 6,095
  • 4
  • 33
  • 72
0

Call alert.create().show();

Refer this link for more details : https://stackoverflow.com/a/13511580/5460053

Community
  • 1
  • 1
Monish Kamble
  • 1,441
  • 1
  • 13
  • 28
  • 1
    @downvoter : can you please explain the reason for the downvote so that i can correct myself. – Monish Kamble Apr 24 '16 at 07:35
  • 1
    I am not not the downvoter but I think it´s bad practise here to downvote without a reason. You get downvoted because it should work normally. If you only using the builder without creating a dialog, show() is enough. – Opiatefuchs Apr 24 '16 at 07:45
  • @Opiatefuchs : Thank You. You are correct. Call to create() is not necessary. Calling show() creates and displays a dialog immediately. – Monish Kamble Apr 24 '16 at 07:53
  • sorry but it dos not work ... i found my problem ...thanks for you @MonishKamble – gh darvishani Apr 24 '16 at 07:56
  • yes, but really, I also thought about that what you have posted because I never seen this way to show a dialog or tested it. Sometimes it´s better to study the API :) ... – Opiatefuchs Apr 24 '16 at 08:01