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.
-
1Layout means, activity? – Nigam Patro Dec 22 '15 at 09:49
-
1You can create this . At first try yourself . – IntelliJ Amiya Dec 22 '15 at 09:50
-
1Search on google Button click to `GONE` another button – IntelliJ Amiya Dec 22 '15 at 09:51
-
1Firtly try at your end and paste your code here..... – Ravindra Kushwaha Dec 22 '15 at 09:54
-
2@RavindraKushwaha Ji well said . – IntelliJ Amiya Dec 22 '15 at 09:55
-
1please tell us, what have you tried? – Androider Dec 22 '15 at 09:55
-
Layout means Xml file – saicharan Dec 22 '15 at 09:56
-
`Please give me a Snippet.` **Why**? This is not how this site works. – Phantômaxx Dec 22 '15 at 10:23
1 Answers
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

- 1
- 1

- 19,130
- 7
- 81
- 94