2

I am developing an android application in which i have several buttons with some text in them. I used these buttons as tags so that when the application installed these 50 buttons will show on screen as tags. Now what i want is that if a user does not want these tags then they can remove the button permanently. i.e. if their is a tag named "Free Delivery" and user doesnot want this then the user can click on the button and if choose Yes then the button of Free Delivery will be deleted permanently and it will not appear next time when user opens the application. How to do this? I have tried this:

button1.setVisibilty(View.GONE);

but when the user open the app next time then the button again showed up Please HELP!

Parsania Hardik
  • 4,593
  • 1
  • 33
  • 33
Arslan Ali
  • 371
  • 5
  • 20

2 Answers2

3

store that button value in DB or SharedPreference and check everytime user opens your application.

if user doesn't want button1 , store that value in Database or Sharedpreference and check if button1 is present then hide it from screen.

if(button1 value in db/preference)
    button1.setVisibility(View.GONE);
Ravi
  • 34,851
  • 21
  • 122
  • 183
2

You can save the preferences of the user with SharedPreferences, it's a way to save information whithout connexion to a database.

Here is the Google's documentation for the SharedPreferences.

You can find how to use them in a already resolved question here

An example of how save a preference :

SharedPreferences preferences = 
PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Name","Alan");
editor.apply();

And here how to get it :

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String name = preferences.getString("Name", null);
Community
  • 1
  • 1
thib sig
  • 164
  • 9
  • Ok, you can find a lot of information with the second link I gave you, but if you don't understand, ask questions here, I will try to help you :) – thib sig Apr 12 '16 at 12:45
  • I tried this but Iam confused what to write here in the value tag because I am not passing string value instead i want to check next time that whether that button was deleted by user or not so what to pass in the value?editor.putString("Name", ); – Arslan Ali Apr 12 '16 at 13:02
  • You can also put int or boolean in shared preferences like this : `editor.putBoolean("tag1", false);` – thib sig Apr 12 '16 at 13:03
  • so when i delete the button then i call shared preference and pass this tag as false? – Arslan Ali Apr 12 '16 at 13:14
  • when you do the action that means _delete the button_, you saved the sharedPreference for this tag at false, and next time when you display the buttons, you check if the sharedPreference for this button is false or true. If it's false, you set it at View.GONE, else View.VISIBLE – thib sig Apr 12 '16 at 13:24
  • you made it ? it is ok ? – thib sig Apr 12 '16 at 13:35
  • Ok great ! Glad I could help you :) – thib sig Apr 12 '16 at 13:37
  • Looking forward to take help from genious like you in future too :) email id if u allowed me? :) – Arslan Ali Apr 12 '16 at 13:40