按钮单击两次

cva*_*len 3 android button

我有一个android的问题,有一个按钮.我编辑了按钮,就像它在开发人员页面中一样,在单击时在文本视图中显示文本,但是当我运行我的应用程序时,我必须按两次按钮才能实现.我认为它可能与焦点有关,但我不确定.

此外,当我应用主题(请参阅样式和主题)时,我甚至必须按两次任何按钮,不仅是上面提到的按钮,而且例如问题中的"是"或"否"按钮退出应用程序(通过对话框)

我搜索了论坛,但没有找到我想要的答案.希望有人能给我一个想法.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    root = (LinearLayout) findViewById(R.id.root);    

((Button) findViewById(R.id.btnZoeken)).setOnClickListener(
            new Button.OnClickListener(){
                @Override
                public void onClick(View arg0) {
                    zoekOpPostcodes(txtZoeken.getText().toString());
                }

                private void zoekOpPostcodes(String zoekterm){

                                                //more irrelevant code
                                         txtResultaat.setText(txtRes);
                            }

//more irrelevant code
private void quit() {
    // prepare the alert box
    AlertDialog.Builder abQuit = new AlertDialog.Builder(this);

    // set the message to display
    abQuit.setMessage("Weet je zeker dat je wil afsluiten?");

    // set a positive/yes button and create a listener
    abQuit.setPositiveButton("Ja", new DialogInterface.OnClickListener() {

        // do something when the button is clicked
        public void onClick(DialogInterface arg0, int arg1) {
            Toast.makeText(getApplicationContext(), "Tot ziens!", Toast.LENGTH_LONG).show();
            iRegionForAndroid.this.finish();
        }
    });

    // set a negative/no button and create a listener
    abQuit.setNegativeButton("Nee", new DialogInterface.OnClickListener() {

        // do something when the button is clicked
        public void onClick(DialogInterface arg0, int arg1) {
            Toast.makeText(getApplicationContext(), "Afsluiten geannuleerd!", Toast.LENGTH_SHORT).show();
        }
    });

    // display box
    abQuit.show();
Run Code Online (Sandbox Code Playgroud)

}

如果您需要更多我的代码,"请问,您将收到":)似乎是"代码"部分的错误,它不包含所有代码,但它的部分在"代码"下部分

use*_*139 17

你可能是正确的,它与焦点有关.

你可能有android:focusableInTouchMode ="true",它需要是假的.第一次单击聚焦于项目,第二次单击调用侦听器.