How to add listview inside viewpager?

How to add listview inside viewpager (without using fragments)? could you help me? Thanks in advance.

+4
source share
4 answers

This will be easy if you use Fragment in the ViewPager , BUT if you do not want to use the ViewPager with a fragment than the ViewPager Without Fragments is an example where you add views and layouts to the ViewPager and are more complex .

A good example is the image gallery, where the user can scroll between different images. On these types of pages, all you really want to display is viewing static content (in this case, an image), how to use ViewPager only with regular views and layouts.

+1
source

It is best to use a snippet for each viewPager page. This way you can maintain individual pages easily .

In your fragment class (the java class that extends the fragment) you can work with your list, for example, initialization, adapt the adapter to the list, set onClickListner for list elements, as in Activity

0
source

ViewPager Activities. " ", FragmentActivity , ViewPager.

0

ViewPager. ViewPager PagerAdapter. ListView , PagerAdapter.

:

<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/home_pannels_pager" />

FragmentActivity :

ViewPager pager = (ViewPager) findViewById (R.id.viewPager); pager.setAdapter( PagerAdapter (getSupportFragmentManager())); simle PagerAdapter:

PagerAdapter FragmentPagerAdapter {

public FrontPageAdapter(FragmentManager Fm) {
    super(Fm);
}

@Override
public Fragment getItem(int position) {
    Bundle arguments = new Bundle();
    arguments.putInt("position", position);
    FragmentPage fragment = new FragmentPage();
    fragment.setArguments(arguments);
    return fragment;
}

@Override
public int getCount() {
    // return count of pages
    return 3;
       }
 }

FragmentPage:

FragmentPage {

public FragmentPage() {}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_frontpage, container, false);  
    // probably cast to ViewGroup and find your ListView          

    Bundle arguments = getArguments();
    int position = b.getInt("position");

    return view;
    }
}

The answer here is fooobar.com/questions/1626829 / ...

0
source

Source: https://habr.com/ru/post/1626828/


All Articles