-2

I have some views in fragment under TabLayout. I want these views to be hidden with 'view.setVisibility' for always (till clearing app data or uninstalling) after a clicking a button. Can somebody help me please. I don't think this question needs any code to show you.

Niezwm
  • 87
  • 1
  • 8
  • 1
    Something like `view.setVisibility(pref.toHide ? GONE : SHOW)` ? I don't get the problem, so you might need to add more information on what you can't do here. – AxelH Jul 07 '17 at 10:43
  • this will surely help you https://stackoverflow.com/questions/44962705/how-to-hide-views-for-always/44962743#44962743 – Adnan Maqbool Jul 07 '17 at 11:14

2 Answers2

2

When the button is clicked set a boolean value as true in SharedPreference.

Then, in onCreate() function of the layout/fragment in which the views are inflated, check the value from SharedPreference and set the visibility accordingly.

taug
  • 378
  • 1
  • 8
  • 1
    @NiezwmxaBoro if you want a solution, first try to implement it yourself. If this doesn't work, edit the question with your latest try, this will be used to give a solution. We are not providing a free coding services. You have the solution, work with it. – AxelH Jul 07 '17 at 11:10
0

You can manage your UI with the SharedPreference. When your onCreateView of fragment is loaded you can check your SharedPreferenceview visible state and apply this flag to view visibility.

Chetan Pushpad
  • 345
  • 1
  • 9
  • What are you adding to [codeWorm](https://stackoverflow.com/a/44968993/4391450) answer ? – AxelH Jul 07 '17 at 11:02
  • It will easy to manage in method onCreateView in fragment. I would suggest you can get the flag in this method and show your UI. – Chetan Pushpad Jul 07 '17 at 11:05
  • But, again, that's already explain in [codeworm answer](https://stackoverflow.com/a/44968993/4391450). Yes, you use a different initialisation method to execute this, but this is just a comment on his answer. – AxelH Jul 07 '17 at 11:08