On Button click i want to toggle the text of TextView in Android Studio : I want to toggle textview text with on a button click .I have set the flag as public variable and change it in onclick function but still the value of flag for some reason is initialized to its default value. i am beginner to android studio
Thank you.


I want text of Textview to toggle every time i click on the button but text of textview changes only once.


    bt1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

    flag=true;
    if(flag=true){
    flag=false;
    txt.setText("Steve");
    }
    else {
    txt.setText("Shetty");
    flag=true;
    }

    }
    });