Android – press the button twice

I have a problem with Android. I have a button. I program the button to view textview when I click, just like displaying text in the developer page, but when I run my application, I have to press my button twice to implement it. I think it may have some focus, but I'm not sure

In addition, when I apply a theme (see styles and themes), I even have to do this by pressing any button twice, not only the button mentioned above, but also, for example, the "yes" or "no" button to exit the question (through dialogue)

I searched the forum, but I didn't find the answer I was looking for. I hope someone can provide me with an idea

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 @R_255_2419@
    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 @R_255_2419@
    abQuit.show();

}

If you still need my code, "excuse me, you will receive":) it seems that there is a problem in the "code" part. It does not contain all the code, but its part is under the "code" part

resolvent:

You may be right. It has something to do with focus

You may have Android: focusableintouchmode = "true", which needs to be false. The first click focuses on the project, and the second click calls the listener

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>