Aarks
Aarks

Reputation: 127

Hide activity button in some fragments and show in some fragments

I have a main activity that includes two buttons 'Submit' and 'Pick' and few images. Inside the activity i have two fragments named MyThings and MyPicks. I want to hide activity button 'Pick' in MyThings fragment but want to show in MyPicks fragment. How can i achieve this? Because i don't know how to initialize the button which is in main activity to that fragment so that i can hide and show button in fragments. Please Help

Upvotes: 1

Views: 1103

Answers (1)

Shayan Tabatabaee
Shayan Tabatabaee

Reputation: 467

There are several ways to handle this situation.

  1. One of them is that you have two methods in your Activity named showButton() and hideButton() and in that methods you hide and show button. In your Fragments you can call these methods in onCreateView() Method since you can invoke Activity methods from Fragment.
  2. Another way is you hide or show button in your Activity when creating and putting Fragment in the container. I prefer the second way.

Upvotes: 3

Related Questions