Adding a standalone snippet other than snippet tabs using the ViewPager
I am having trouble adding Fragment
other than Fragments
which I linked to each of mine Tabs
. In other words, I want to be able to scroll between Fragments
using ViewPager
, but I don't want the first Fragment
one to be one of Tabs
.
My is Adpater
for ViewPager
and mine Tabs
is basically the one Google gives in the developer website .
I tried to go ahead and add Fragment
which I want to separate from the other in TabHost
like a tab and then set the visibility TabWidget
to GONE at position 0 and although that will remove TabWidget
when I go to any other position the tab for position 0 will still be there. This method is a little clunky and I would prefer to implement it better.
I would share some code, but most of it is hosted on the Developers website, but if I need it I will.
source to share
I think I have a similar thing in my application. I have a set of action bar tabs, each of which is its own fragment. When you click on certain buttons on a tab, another snippet is triggered. Obviously you know all about the ViewPager, the TabListener solution, etc. But my solution starts another snippet that fills the whole screen. When you click back (focused on the new snippet) it takes you back to where you were in the action bar tab action. Here's a snippet of code that starts a new snippet:
public class EconFragment extends Fragment {
private ViewGroup container;
private TableLayout questionContainer;
private ScrollView scrollView;
private ViewGroup econFragment;
private View[] questions;
static int pos = 0;
private String[] titles = {"The first title ", "hallo1","hallo2", "hallo3",
"hallo4", "hallo5","hallo6", "hallo7","hallo8", "hallo9"};
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d("Econ", "onCreateView");
this.container = container;
return inflater.inflate(R.layout.econfragment, container, false);
}
public OnClickListener chartsListener = new OnClickListener() {
public void onClick(View v) {
Intent chart = new Intent();
chart.setClass(getActivity(), Chart.class);
chart.putExtra("key", titles[v.getId()]);
Log.v("TAG", Integer.toString(v.getId()));
startActivity(chart);
}
};
As you can see, I am launching a new intent called diagram. Then the chart class is set to Chart - which extends the snippet. Here's a discussion that led me to this implementation: Start a fragment with an Intent inside a fragment
source to share