0

I Want to show AlertDialog on RecyclerView,
but have error :

You need to use a Theme.AppCompat theme (or descendant) with this activity

but show Toast Successfully!

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.ProjectsViewHolder> {

....

    public RecycleAdapter(ArrayList<ProjectsInfo> projectsInfos, Context context){
        this.projectsInfos = projectsInfos;

        this.context = context;
    }

    public void onBindViewHolder(ProjectsViewHolder holder, final int position) {
            ProjectsInfo getProjectInfos = projectsInfos.get(position);
            holder.imgProject.setImageResource(getProjectInfos.img);
            holder.txtSubject.setText(getProjectInfos.subject);
            holder.txtStr.setText(getProjectInfos.str);

            holder.txtSubject.setTypeface(BaseActivity.typeface);
            holder.txtStr.setTypeface(BaseActivity.typeface);

            holder.linearLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //worked
                    //Toast.makeText(context, "Clicked item "+position, Toast.LENGTH_SHORT).show();

                    //not work
                    AlertDialog.Builder builder = new AlertDialog.Builder(context)
                            .setIcon(android.R.drawable.btn_dialog)
                            .setMessage("test"
                            )
                            .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            });
                    builder.create().show();

                }
            });
        }

        ....

}

In thread using:

    public class Projeha extends AppCompatActivity {
...

    thread = new Thread(new Runnable() {
    ...
        recyclerView.setAdapter(new RecycleAdapter(setProjectInfo,getApplicationContext()));
    });
....
}

Where is problem?

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
  • Check answer: https://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity – Tung Tran Apr 14 '18 at 08:23

2 Answers2

0
 AlertDialog.Builder builder = new AlertDialog.Builder(context)

Instance of use this

 AlertDialog.Builder builder = new AlertDialog.Builder(v.getcontext)

change this

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(v.getcontext);
      alertDialogBuilder.setMessage("Are you sure,
         You wanted to make decision");
      alertDialogBuilder.setPositiveButton("yes", 
         new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface arg0, int arg1) {
            Log.e("You clicked yes","");

         }
      });

      alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
         Override
         public void onClick(DialogInterface dialog, int which) {
           Log.e("You clicked NO","");
         }
      });

      AlertDialog alertDialog = alertDialogBuilder.create();
      alertDialog.show();

Check here official doc : https://developer.android.com/guide/topics/ui/dialogs.html

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
-1

just call this method

builder.show();
kemdo
  • 1,429
  • 3
  • 15
  • 29