I have researched and tried to learn, but I am unclear and would appreciate help. I have played with a few different strategies, but cannot figure this out though this is really basic stuff.
I have a FragmentPagerAdapter that returns the tab name and the content text from a string. Those views or fragments--I'm so new I'm unclear on the terminology--are swipeable, which is great! (I followed numerous tutorials and examples.)
Now I want to add a ListView to scroll through the thirty or so fixed content texts that are displayed as users swipe.
Here, I think, is the relevant code so far:
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
Log.v(TAG, "getPageTitle");
String tabTitle = null;
switch(position) {
case 0:
tabTitle = "FAQs";
break;
case 1:
tabTitle = "Content";
break; return tabTitle;
}
/** This method will be invoked when a page is requested to create */
@Override
public Fragment getItem(int arg0) {
MyFragment myFragment = new MyFragment();
Bundle data = new Bundle();
data.putInt("current_page", arg0+1);
myFragment.setArguments(data);
return myFragment;
}
/** Returns the number of pages */
@Override
public int getCount() {
return PAGE_COUNT;
}
}
and the ViewPager:
public class Content extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contentpage);
/** Getting a reference to the ViewPager defined the layout file */
ViewPager pager = (ViewPager) findViewById(R.id.pager);
/** Getting fragment manager */
FragmentManager fm = getSupportFragmentManager();
/** Instantiating FragmentPagerAdapter */
MyFragmentPagerAdapter pagerAdapter = new MyFragmentPagerAdapter(fm);
/** Setting the pagerAdapter to the pager object */
pager.setAdapter(pagerAdapter);
}
}
and
public class MyFragment extends Fragment{
int mCurrentPage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Getting the arguments to the Bundle object */
Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPage = data.getInt("current_page", 0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.myfragment_layout, container,false);
TextView tv = (TextView ) v.findViewById(R.id.tv);
tv.setMovementMethod(new ScrollingMovementMethod());
switch(mCurrentPage){
case 0:
tv.setText(" ");
break;
case 1:
tv.setText(R.string.faqs);
break;
case 2:
}
return tv;
}
What I want to do is create a ListView that is a shortcut to the items returned in the content fragments.The ListView should display the tabTitles and when they are clicked, the user should be taken to the content page that is swipeable.
What do I put in ListView.java?
public class ListView {
}
Thank you in advance for any help you can offer.