In custom dialog class with the custom view, I want to handle click of the button from Activity or fragment, I have created an interface for handling the button click but showing error.
Attempt to invoke interface method 'void com.ymcaspi.util.CustomDialog$DialogInterface.doLogin(com.ymcaspi.util.CustomDialog)' on a null object reference
My dialog class is
public class CustomDialog extends Dialog implements
android.view.View.OnClickListener {
public Activity activity;
public Button btnYes, btnNo;
CustomDialog customDialog;
public CustomDialog(Activity activity) {
super(activity);
this.activity = activity;
}
DialogInterface dialogInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.alert_login);
btnYes = (Button) findViewById(R.id.btn_yes);
btnNo = (Button) findViewById(R.id.btn_no);
btnYes.setOnClickListener(this);
btnNo.setOnClickListener(this);
}
//in custom adapter class i want to handle click of button from Activity or fragment, I have created a interface for handling button click
//but showing
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
customDialog=new CustomDialog(activity);
dialogInterface.doLogin(customDialog);
break;
case R.id.btn_no:
dismiss();
break;
default:
break;
}
dismiss();
}
public interface DialogInterface{
void doLogin(CustomDialog dialog);
}
}
i have implemented this interface in fragment but not working?