按钮单击两次

时间:2011-01-10 17:56:52

标签: android button

我有一个Android问题,有一个按钮。我编程了 按钮就像在开发人员页面中显示文本一样 单击时查看textview,但是当我运行我的应用程序时,我必须按 我的按钮两次,以实现它。我以为它可能有所作为 与焦点有关,但我不确定。

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

我搜索了论坛,但没找到 我正在寻找的答案。希望有人可以提供给我一个 想法。

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

}

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

1 个答案:

答案 0 :(得分:17)

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

你可能有android:focusableInTouchMode =“true”,它必须是false。第一次单击专注于项目,第二次单击调用侦听器。

相关问题