-5

In Android For example,We have four Buttons in first Layout.And we have 10 Buttons in second Layout. If we clicked on any one Button out of 4 buttons,in next layout any 5 buttons has to Visible and remaining 5 buttons need to Invisible.I did not getting the Logic.Please give me a Snippet.Thanks in Advance.

Panda
  • 1,231
  • 18
  • 27
saicharan
  • 1
  • 3

1 Answers1

0

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

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94