I create one activity(Home activity)inside home activity I add frame layout & some buttons. in frame layout I load fragment(Home fragment)inside home fragment I create Tab Layout now my question is when we select button(from home activity)so change regarding tab is their any possible way??
Note: I can not use viewpager because of some reason
my flow is
(1) Activity->frame layout && buttons
(2) frame layout-> load fragment(Home fragment)-> tab layout-> new frame layout which contains diff. fragment regarding tabs.
when click on activity's button so change tab
Thanks in advance
Try this :
yourTabLayout.getTabAt(tabPosition).select();
tabPosition is an int that determinants which tab will be selected
For example : 0 will select the first tab, 1 will select the second tab, 2 will select the third tab and so on
Related
I am trying to implement a side-navigation bar (hamburger menu). I want to be able to select a new fragment to view from this menu, and then click buttons on that fragment to direct to another fragment (not in the hamburger menu list).
I was following a guide (https://www.youtube.com/watch?v=bjYstsO1PgI), but it doesn't show the second step of redirecting to the other fragment.
I keep getting a crash whenever I click a button that redirects to the other fragment, if it has been loaded by the hamburger menu.
The line I use is to render from the hamburger menu is:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new FirstFragment()).commit();
This is called by the following event listener:
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
and I get this error whenever I press a button to go to the 'other' fragment.
Navigation action/destination com.example.testApp:id/action_FirstFragment_to_submitScreen cannot be found from the current destination Destination(com.example.testApp:id/submitScreen) label=fragment_submit_screen class=com.example.renamedTestApp.SubmitScreen
This error is not present when I use
<include layout="#layout/content_main"/>
to load the first fragment on app startup (the one from the hamburger menu).
Any tips? This question may be confusing so let me know if I should tidy up my explanation.
I believe the error may be in the fragment not being fully loaded perhaps? If that is the case, what would be a better line to use to switch on the fly.
provide some code
try this
FragmentManager fragmnt= getActivity().getSupportFragmentManager();
FragmentTransaction tr= fragmnt.beginTransaction();
tr.replace(R.id.YOUR,new Yourfragment());
//or tr.replace(R.id.content_frame, new Yourfragment());
tr.commit();
This is what I'm hoping to achieve:
Step 1: Click on the Green Button to open View1.xml on the ViewPager. (Works)
Step 2: Click on the Orange Button to open SubView.xml on the ViewPager. (Doesn't work)
So, I have set the onClick event for the orange button the following:
public void openForm(View view) {
ViewGroup item = (ViewGroup)findViewById(R.id.vp_horizontal_ntb); //this is the view pager
View child = getLayoutInflater().inflate(R.layout.activity_post_form, null);
item.addView(child);
}
Results:
Nothing. Nothing happens.
If I switch viewpager for linearlayout it opens (and breaks tab navigation). What I wanna do is open it on the viewpager, so it looks and behaves as if it's on a tab, until it's removed by clicking on another tab.
I also thought about putting a linear layout there and make viewPager gone while the linearLayout is set to visible. But I feel like there's a better solution than this.
I'm trying to use SmartTabLayout from here https://github.com/ogaclejapan/SmartTabLayout, and i have a drawer. When i'm clicking at item on drawer, i replace my fragment, to fragment with smarttablayout. For first time it's ok, smarttablayout have tabs with content, but when i click in drawer on the same item, content of tabs just disappear, and to show them back i have to scroll to the end, and scroll back, to show them. I don't have idea why.
Notes: If using fragment inside a ViewPager, Must be use Fragment#getChildFragmentManager().
https://github.com/ogaclejapan/SmartTabLayout#pageradapter-for-fragment-based-page
FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
getChildFragmentManager(), FragmentPagerItems.with(this.getA())
.add(R.string.item_pager_title_products, ProductListFragment.class)
.add(R.string.item_pager_title_shops, ShopListFragment.class)
.create());
FYI: Had same problem because I didn't read the manual... Original answer found here https://stackoverflow.com/a/25525714/1257369
I have a 2 fragments, fragment adapter, sliding tab layout, sliding tab strip and main activity.
How do i change the action bar text when i change tab like when user select tab1 the action bar text is home and tab 2 action bat text is profile.
also how do i change to tab text to icon.
for my final year project please help thanks :D
Guide for the sliding tab: http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html
it crashed when i add
getActivity().getActionBar().setTitile("required title as per
fragment");
in the fragment #Override onResume
LogCat error Attempt to invoke virtual method 'void
android.app.ActionBar.setTitle(java.lang.CharSequence)' on a null
object reference
In onResume() of each fragment you can get actionbar like getActivity().getActionBar().setTitile("required title as per fragment");
i hope this will solve you problem
In Vaadin, say I have a Tabsheet, with several Tabs.
If I want to add subtabs to any of the Tabs in the Tabsheet, based on which Tab the subtabs have as their "parent" tab , how do I do this?
Tabs are identified by the Component they hold. So, basically addanother TabSheet as a Tab to have subtabs:
TabSheet tabs = new TabSheet();
TabSheet subTabs = new TabSheet();
tabs.addTab(subTabs, "Parent tab",null);
subTabs.addTab(new Label("Subtab content"), "Subtab",null);