I have a problem with my Dialog Fragment. I wanted to use android:onClick attribute as in my opinion code is more clear then.
In my layout I have the following declarati
I would try a different approach which works fine for me:
implement an OnClickListener into your fragment:
public class DialogNewDatabase extends DialogFragment implements OnClickListener`
have a button with an unique id in xml, which does NOT need android:clickable
override the method onClick()
within your fragment and insert a reaction on your click:
public void onClick(View v) {
switch (v.getId()) {
case R.id.dialog_new_database_button_cancel:
// your stuff here
this.dismiss();
break;
default:
break;
}
}
import the necessary:
import android.view.View.OnClickListener;
start the onClickListener on the button:
private Button bCancel = null;
bCancel = (Button) findViewById(R.id.dialog_new_database_button_cancel);
bCancel.setOnClickListener(this);
// it is possible that you might need the refrence to the view.
// replace 2nd line with (Button) getView().findViewById(...);
This way you can handle even more clickable buttons in the same onClick-method. You just need to add more cases with the proper ids of your clickable widgets.