android - Where have I to define the onclick for button in customized dialog? -


I have found a dialog in a dialog. It works fine.

I use a custom layout for my dialogue. These are two buttons

release_scan_dialog.xml

   & Lt; Button Android: id = "@ + id / storage" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: text = "scan2" /> & Lt; / LinearLayout & gt;   

ScanFragment.java

  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; }}   

If I try to define onClick for both buttons then is NullPointerException . Thanks to any response to onClick

which is the correct event.

release_scan_dialog within the inflated view with layout = "text">

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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -