I have an Adapter which extend ArrayAdapter
. With this adapter class I manage a ListView
inside MainActivity.
I also have some buttons inside each row of the list and when I click on a button I want an AlertDialog
to be shown. In doing so, I got an error about Theme
.
I read about changing theme inside my manifest, but it does not work even if I change.
holder.delete=(ImageButton)row.findViewById(R.id.delete_btn_item);
holder.delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder dialog= new AlertDialog.Builder(getContext());
dialog.setTitle("Deleting...");
dialog.setMessage("You are deleting DEFINITELY <" + db.getAllRecipes().get(position).getRec_name() + ">. Are you sure to continue?");
dialog.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.deleteRecipe(db.getAllRecipes().get(position));
dialog.dismiss();
Toast.makeText(getContext(), "deleted " + db.getAllRecipes().get(position).getRec_name(), Toast.LENGTH_SHORT).show();
}
});
dialog.create();
dialog.show();
}
});
I have the holder inside the getView method. My first code lines are:
public class RecipeAdapter extends ArrayAdapter {
DatabaseHelper db;
LayoutInflater layoutInflater;
private Context context;
PopupWindow popUpWndw;
List list= new ArrayList();
public RecipeAdapter(Context context, int resource) {
super(context, resource);
this.context = context;
db=new DatabaseHelper(context.getApplicationContext());
}
The error I get is this:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.