android - Where have I to define the onclick for button in customized dialog? -
I have found a dialog in a I use a custom layout for my dialogue. These are two buttons release_scan_dialog.xml ScanFragment.java If I try to define which is the correct event. dialog. It works fine.
public class ScanFragment extends DialogFragment {public Android. app.Dialog onCreateDialog (android.os.Bundle savedInstanceState) {AlertDialog dialog = new AlertDialog.Builder (this.getActivity ()) .setView (this.getActivity (). getLayoutInflater (). add (R.layout.release_scan_dialog, null) ) .setTitle (R.string.title_store) .setPositiveButton (android.R.string.ok, new DialogInterface.OnClickListener () {@Override public void onClick (DialogInterface dialog, int which) {}}) .setNegativeButton (android.R .string.cancel, New DialogInterface.OnClickListener () {@Override Click on Public Zero (DialogInterface dialog, int which) {}} .create (); dialog.setOnShowListener (New DialogInterface.OnShowListener () {@Override public void onShow (DialogInterface dialog) {((AlertDialog) dialog) .getButton (AlertDialog.BUTTON_POSITIVE) .setEnabled (false);}}); // This is a NullPointerException dialog.findViewById (R.id.code) .setOnClickListener (New OnClickListener () {@Override see public void onClick () {((AlertDialog) getDialog ()). GetButton (will crush with AlertDialog.BUTTON_POSITIVE) .setEnabled (true);}}); Return dialog; }}
onClick for both buttons then
is NullPointerException . Thanks to any response to
onClick
code Button can be found.
public class ScanFragment DialogFragment extended {public android.app.Dialog onCreateDialog (android.os.Bundle savedInstanceState) inflates scene {// release_scan_dialog layout. Final View release_scan_view = getActivity () GetLayoutInflater (). Fulao (R. Late .rele_scan_dialog, blank); AlertDialog dialog = new AlertDialog.Builder (this.getActivity ()) .setView (release_scan_view) .setTitle (R.string.title_store) .setPositiveButton (android.R.string.ok, New DialogInterface.OnClickListener () {@Override public void onClick (DialogInterface dialog, int which) {}}) .setNegativeButton (android.R.string.cancel, new DialogInterface.OnClickListener () {@Override public void onClick (DialogInterface dialog, int which) {}}) .create () ; dialog.setOnShowListener (New DialogInterface.OnShowListener () {@Override public void onShow (DialogInterface dialog) {((AlertDialog) dialog) .getButton (AlertDialog.BUTTON_POSITIVE) .setEnabled (false);}}); // Release_scan_dialog Set OnClickListener for the 'Code' button in the layout. release_scan_view.findViewById (R.id.code) .setOnClickListener (New OnClickListener () {@Override see public void onClick () {((AlertDialog) getDialog ()) getButton (AlertDialog.BUTTON_POSITIVE) .setEnabled (right) ;.}} ); Return dialog; }}
Comments
Post a Comment