gpt4 book ai didi

android - 如何在android中实现OnCancel监听器

转载 作者:太空狗 更新时间:2023-10-29 15:20:35 25 4
gpt4 key购买 nike

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();

}
}


}

我这样调用它,其中模态是一个按钮

modal.setOnClickListener(new View.OnClickListener() {

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

我收到以下错误

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. <init>(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)

我想在调用 onCancel 函数后获取变量 Capacity、Color 等的值。现在对话框挂起并在将值放入变量之前完成。谁能建议我该怎么做?

提前致谢

最佳答案

为什么不在调用 cancel() 之前在 onclick 方法中获取值?

关于android - 如何在android中实现OnCancel监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8187350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com