lundi 8 novembre 2021

Java code to show action on x amount of presses?

I have an iOS app that I worked on some time ago, and the function it uses I like, and would like to somehow get it to work on some Android code I have.

At the top of my MainActivity I have

SharedPreferences sharedpreferences;

public static final String MyPREFERENCES = "nShownLobby";

on my onCreate I have

sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);

And I am calling this method

changeTextButton.setOnClickListener(new View.OnClickListener() {
    
    @Override
    public void onClick(View v){
        long nb_shown_lobby = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).getLong("nShownLobby", 0); 
        ++nb_shown_lobby; 
        if ((nb_shown_lobby % 20) == 0) { 
            this.turnAround(); 
        }
        int random = (int) (Math.random() * manyDifferentStrings.length);
        if (random == oldVaue) {
            random = (int) (Math.random() * manyDifferentStrings.length);
        }
        changingText.setText(manyDifferentStrings[random]);
        oldVaue = random;
        try {
            mySound.start();
        } catch (NullPointerException e) {
            mySound = MediaPlayer.create(MainActivity.this, R.raw.sound);
        }
    }

    private void turnAround() {
        //Do something here
        Log.i("Do Something ", "");
    }
});

The intention is that after every 20 presses, the turnAround() method is called but it does not... It just gets ignored - I am guessing I have missed something?




Aucun commentaire:

Enregistrer un commentaire