gpt4 book ai didi

java - 在对话框的自定义 View 中处理返回键

转载 作者:行者123 更新时间:2023-11-30 04:12:44 25 4
gpt4 key购买 nike

好吧,我在对话框中有一个自定义 View ,但它的 onKeyDown 永远不会被调用。我也试过 onKeyPreIme 但没有用,将对话框的 setCancelable 设置为 true 也没有帮助。

编辑:

//Removed all unnecessary code

public class CustomView extends LinearLayout
{

@Override
public boolean onKeyDown (int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{
//do stuff here
return true;

}
return super.onKeyDown(keyCode, event);
}
}
public class CustomDialog
{
Dialog dialog;
public class CustomDialog(Context context)
{
dialog = new Dialog(context);
dialog.setContentView(R.layout.test);// the test.xml has CustomView

}

}

最佳答案

你为什么不简单地使用:

public void onBackPressed() {
//desired functionality here
return;
}

关于java - 在对话框的自定义 View 中处理返回键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10569702/

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