[Solved] How to get the buttons Visibility in Second layout when clicked a button in First layout? [closed]


In first layout class use SharedPreferences to store a boolean values which buttons was clicked. In second layout class you would read these values and take some actions.

To make button invisible (programmatically):

Set button visibility to GONE (button will be completely “removed” — the buttons space will be available for another widgets) or INVISIBLE (button will became “transparent” — its space will not be available for another widgets):

View b = findViewById(R.id.button);
b.setVisibility(View.GONE);

Using SharedPreferences

Just read: How to use SharedPreferences in Android to store, fetch and edit values

Save any button state

According to How to check if a user has already clicked a Button?

You can save a flag in shared preferences if the user clicks the
button. Next time, you can check in the shared preferences if there
exists the flag.

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    SharedPreferences pref = getSharedPreferences("promo", MODE_PRIVATE);
    boolean activated = pref.getBoolean("activated", false);
    if(activated == false) {  // User hasn't actived the promocode -> activate it 
        SharedPreferences.Editor editor = pref.edit();
        editor.putBoolean("activated", true);
        editor.commit();
    } 
}

If you still have any question, please free to ask

Hope it help

solved How to get the buttons Visibility in Second layout when clicked a button in First layout? [closed]