How to add a custom view to the ViewPager for a walkthrough

I used ViewPagerIndicator to get WalkThrough as the most popular app. But I can’t figure out how to add Pictures to ViewPager, which shows how to use the application.

Walk through I want these Walks to go.

Where i went toWhere i went to What I got so far.

I dont know

How to add a custom look, for example ImageView, and TextViewin ViewPager?

Any advice would be appreciated.

+4
source share
2 answers

According to Inteist, you can put any fragment into a fragment and provide this fragment to the adapter.

Fragment:

    public final class SelectModelFragment extends Fragment {
    private static final String KEY_CONTENT = "SelectModelFragment:Content";
    private static String TAG = SelectModelFragment.class.getSimpleName();

    private SelectModel mSelectModelObj;

    private CircularImageView mImageView;

    public static SelectModelFragment newInstance(SelectModel obj) {
        SelectModelFragment fragment = new SelectModelFragment();
        fragment.mSelectModelObj =obj;

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
            mSelectModelObj = savedInstanceState.getParcelable(KEY_CONTENT);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_select_model, container, false);
        mImageView = (CircularImageView)view.findViewById(R.id.fragment_select_model_iv);
        return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable(KEY_CONTENT, mSelectModelObj);
    }
}

Fragment Adapter:

public class SelectModelAdapter extends FragmentPagerAdapter {

    ArrayList<SelectModel> mList;
    private int mCount;
    private static final String TAG = SelectModelAdapter.class.getSimpleName();

    public SelectModelAdapter(FragmentManager fm, ArrayList<SelectModel> mList) {
        super(fm);
        this.mList = mList;
        mCount =  mList.size();
    }

    @Override
    public Fragment getItem(int position) {
        return SelectModelFragment.newInstance(mList.get(position));
    }

    @Override
    public int getCount() {
        return mCount;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return TAG;
    }

    public void setCount(int count) {
        if (count > 0 && count <= 10) {
            mCount = count;
            notifyDataSetChanged();
        }
    }
}

: ViewPager Fragment Adapter, .

public class SelectModelActivity extends BaseSliderActivity {

    private ViewPager mPager;
    private SelectModelAdapter mAdapter;

    private ArrayList<SelectModel> mList;
    private void setAdapter() {
            mAdapter = new SelectModelAdapter(getSupportFragmentManager(), mList);
            mPager.setAdapter(mAdapter);
            mIndicator.setViewPager(mPager);
        }
}
0

, :

viewpager , , viewpager. , / ..

0

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


All Articles