I am very new to android programming and I am trying to implement tabs using fragments. I am using this Tutorial. Everything goes fine but my problem is that I want to open a new activity and on this new activity I want to keep tab bar. I want tab bar visible on every new activity which opens inside tab. I have following code..
public class Tab1Fragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
LinearLayout theLayout = (LinearLayout) inflater.inflate(
R.layout.tab_frag1_layout, container, false);
// Register for the Button.OnClick event
Button b = (Button) theLayout.findViewById(R.id.btn_startActivity);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Tab1Fragment.this.getActivity(),
"open new activity with tab bar", Toast.LENGTH_LONG).show();
//Here I want to start new activity with tab bar
}
});
return theLayout;
// return (LinearLayout)inflater.inflate(R.layout.tab_frag1_layout,
// container, false);
}
}
Here is Main Activity.
and layout of this MainActivity.
Fragment1:
Fragment2:
Fragment3:
FragmentChangeListener Interface.
DummyTabFactory:
CustomFragemnt:
CustomAdapter:
BaseFragment:
Layout for AnotherFragment.
Layout for CustomFragment:
Layout for Frament1:
Layout for Fragment2:
Layout for Fragment3:
Layout for Row.xml
Tab.xml
My suggestion is you should you fragments instead on using new activity. Fragment will be displayed withing your current activity and you don't need to take care about tabs.
but if your need is to use Activity then Create tabhost in newActivity layout as well as you made in this Activity's Layout. and while creating intent of another activity, send the current Tab number in extras to new Activity.
In New Activity.
Hope this will helpful.