STEP 1: viewpager xml file
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"/>
|
STEP 2: ViewPagerAdapter class
Context c;
private List<String> _imagePaths;
private LayoutInflater inflater;
public ViewPagerAdapter (Context c, List<String> imagePaths) {
this._imagePaths = imagePaths;
this.c = c;
}
@Override public int getCount() {
return this._imagePaths.size();
}
@Override public boolean isViewFromObject(View view, Object object) {
return view == (object);
}
@Override public Object instantiateItem(ViewGroup container, int position) {
ImageView imgDisplay;
inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.product_viewpager_image, container,
false);
imgDisplay = (ImageView) viewLayout.findViewById(R.id.image);
Glide.with(c).load(_imagePaths.get(position)).
placeholder(R.drawable.about).error(R.drawable.about).into(imgDisplay);
(container).addView(viewLayout);
return viewLayout;
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
(container).removeView((RelativeLayout) object);
}
}
|
STEP3:main activity code:
List<String> images=new ArrayList<>();
ViewPager viewpager = (ViewPager) findViewById(R.id.pager);
images.add("imageurl");
images.add("imageurl");
images.add("imageurl");
images.add("imageurl");
ViewPagerAdapter adapter = new ViewPagerAdapter (MainActivity.this, images);
viewpager.setAdapter(adapter);
|
can i use getter and setter instead of url to get the image from firebase database.And if i can can u please guide me how to do it
ReplyDeleteThank you very much sir.
ReplyDeleteThis is very useful for me.
ReplyDeleteCan you please share json response and will it work for latest android studio 4.0
ReplyDeleteI Have Same Problem ....
Delete非常感谢
ReplyDelete