how to implement OnCancel listener in android
<pre><code>public class ModalityDialog extends Dialog implements OnClickListener, OnCancelListener {
EditText capacity ;
EditText color ;
Button modal_ok ;

String Capacity;
String Color;

public ModalityDialog(Context context) {
    super(context);
    /** It will hide the title */
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.preferences);

    capacity = (EditText)findViewById(R.id.capacityInput);      
    color = (EditText)findViewById(R.id.ColorInput);        
    Button modal_ok = (Button)findViewById(R.id.modality_ok);
    modal_ok.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    if (v == modal_ok){

        cancel();
    }
}

@Override
public void onCancel( DialogInterface dialog ){
    if( dialog == this){
        Capacity = capacity.getText().toString();           
        Color = color.getText().toString();

    }
}


 }
</code></pre>

<p>I call it as follows where modal is a button</p>

<pre><code>modal.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ModalityDialog modalDialog = new ModalityDialog(InputInfo.this);
            modalDialog.show();}
    });
</code></pre>

<p>I am getting the following error</p>

<pre><code>11-19 03:30:00.733: E/AndroidRuntime(305): FATAL EXCEPTION: main
11-19 03:30:00.733: E/AndroidRuntime(305): java.lang.NullPointerException
11-19 03:30:00.733: E/AndroidRuntime(305):  at com.domain.ActivityEx.ModalityDialog.   &lt;init&gt;(ModalityDialog.java:38)
11-19 03:30:00.733: E/AndroidRuntime(305):  at  com.domain.ActivityEx.InputInfo$1.onClick(InputInfo.java:57)
11-19 03:30:00.733: E/AndroidRuntime(305):  at android.view.View.performClick(View.java:2408)
11-19 03:30:00.733: E/AndroidRuntime(305):  at android.view.View$PerformClick.run(View.java:8816)
11-19 03:30:00.733: E/AndroidRuntime(305):  at android.os.Handler.handleCallback(Handler.java:587)
11-19 03:30:00.733: E/AndroidRuntime(305):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-19 03:30:00.733: E/AndroidRuntime(305):  at android.os.Looper.loop(Looper.java:123)
11-19 03:30:00.733: E/AndroidRuntime(305):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-19 03:30:00.733: E/AndroidRuntime(305):  at java.lang.reflect.Method.invokeNative(Native Method)
11-19 03:30:00.733: E/AndroidRuntime(305):  at java.lang.reflect.Method.invoke(Method.java:521)
11-19 03:30:00.733: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-19 03:30:00.733: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-19 03:30:00.733: E/AndroidRuntime(305):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>I want to get the values of variables Capacity, Color, etc. after onCancel function has been called. Right now the dialog box hangs and finishes before putting the values in the variables. Can anyone suggest how can I do so ?</p>

<p>Thanks in advance</p>
