Reputation: 67
I am learning android development, and while making an app i am facing a trouble for which I need suggestion to learn and implement.
I have a layout (layout_view_1) associated with an activity (Activity 1) as in the image below. I have 3 clickable layouts with image and text (button like behavior). On click of these button like layout I want the view to change like shown in layout_view_2. On click of the 3 button like layouts I want to load different screens with changing information (Tab like results).
I can use really tab like thing with Swipe Views / fragment but I want the the look not like tab (with text) with big button like image with text.
So what I did is, create 3 different layouts, make 3 different activities, associate each activity with each layout. On click from the Activity 1 I am launching an intent with the activity class. I get but desired results.
What I want to know is, is there a way to make the same result without creating so many activities? I mean, lo load the layout (result view) of the desired button with the button background changed to selected like effect and switching the buttons to change view. Just like a tabbed window in desktop application.
What I want: On click of each top button open a screen with specific options
What I did: Create multiple activities for each button event using intent
What I don't like: So many activities
What I expect: An idea to show multiple screen for each button events using 1 activity (i.r, Activity 1)
Image of layouts and desired results:
Upvotes: 0
Views: 15244
Reputation: 274
For tabbed window try to use a Viewpager with Fragments inside. And if you want style your tabs, just have a look for TabLayout. Good luck!
Upvotes: 0
Reputation: 175
You can make three layout in your activity, where two of them are invisible
setVisibility(View.GONE);
When you click your button hidde the actual layout and display another one :
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
layoutone.setVisibility(View.GONE);
layouttwo.setVisibility(View.GONE);
}});
Upvotes: 3