I have an activity that in the lower part of the same position a ViewPager where I intend to add an edit-text and a couple of buttons.
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
// List of fragments which are going to set in the view pager widget
List<Fragment> fragments;
/**
* Constructor
*
* @param fm interface for interacting with Fragment objects inside of an
* Activity
*/
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
this.fragments = new ArrayList<Fragment>();
}
/**
* Add a new fragment in the list.
*
* @param fragment a new fragment
*/
public void addFragment(Fragment fragment) {
this.fragments.add(fragment);
}
@Override
public Fragment getItem(int arg0) {
return this.fragments.get(arg0);
}
@Override
public int getCount() {
return this.fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return "Página " + (position + 1);
}
}
Currently I have four pages where I load a background color and a text in this way.
MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(
getSupportFragmentManager());
adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
.getColor(R.color.positivo), 0));
adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
.getColor(R.color.negativo), 1));
adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
.getColor(R.color.positivo), 2));
adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
.getColor(R.color.negativo), 3));
adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
.getColor(R.color.positivo), 4));
this.pager.setAdapter(adapter);
This is done in the java file of the activity where I want the ViewPager to run.
I have two doubts: how would a test xml where two buttons and an edit_text appear in a drawable resource file? and how can I load that generated xml, in the java file where I set the content of the ViewPager if it were in the drawable folder?