this dialog has two options. I want to dismiss a dialog by touching background but I don't know how.
public void dialog( long id) {
final int position=(int) id;
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_checkbox);
// set the custom dialog components - text, image and button
Button yes = (Button) dialog.findViewById(R.id.yes);
Button no = (Button) dialog.findViewById(R.id.no);
yes.setTypeface(type);
no.setTypeface(type);
// if button is clicked, close the custom dialog
yes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String number=contactnumber.get(position);
String name=contactname.get(position);
contactnumber.remove(position);
contactname.remove(position);
adapter.notifyDataSetChanged();
dialog.dismiss();
str="del";
delete(name, number);
}});
no.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
edit(position);
dialog.dismiss();
}});
dialog.show();
DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
dialog.getWindow().setLayout((6 * width)/7, LayoutParams.WRAP_CONTENT);
}
I use this but not work
LinearLayout background = (LinearLayout) findViewById(R.id.back);
background.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SetBackground();
// here I want to dismiss it after SetBackground() method
OptionDialog.dismiss();
}
});
The method SetBackground() is undefined for the type new View.OnClickListener()