Double click

I have a problem with Android, with a button. I programmed as on the developer pages to display text in a textview when clicked, but when I launch my application, I have to click my button twice for this to happen. I thought this might be something to do with focus, but I'm not sure.

In addition, when I apply a theme (see styles and themes), I even have to press any button twice, not just the button indicated above, but for example, the yes or no button in the question about leaving the application ( through the dialog box)

I searched for forums for this, but did not find the answer I was looking for. Hope someone can provide me 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 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();

}

, ", ":) , - "code", , "code"

+3
1

, , .

android: focusableInTouchMode = "true", . , .

+17

Source: https://habr.com/ru/post/1784581/


All Articles