First I have to say that I am not good at English and "brand new" for Android programming.
I want to create an application, such as an Android Android screen, that can move left and right to see views. In my application, each view has a button to do something; Now I have done the sliding part with ViewPager and Fragments. When I launch my application, it can smoothly move left-right, but I canβt find a solution to make a button work in each view. How can i do this? Thanks so much for each of your answers. The following is my code (I changed it from examples over the Internet).
This main fragment class contains many fragments.
public class LessonsActivity extends FragmentActivity{ private PagerAdapter mPagerAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.viewpager_layout);
}
The following is the snippet class that I used to display the layout.
public class Lesson_1 extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) {
}
And this is my PagerAdapterClass
public class PagerAdapter extends FragmentPagerAdapter { private List<Fragment> fragments; public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Override public Fragment getItem(int position) { return this.fragments.get(position); } @Override public int getCount() { return this.fragments.size(); }
}
source share