Add Multiple Images And Text To Each Viewpager Slide
Solution 1:
publicclassViewPagerAdapter2extendsPagerAdapter {
Context context;
String[] image1;
String[] description;
LayoutInflater inflater;
publicViewPagerAdapter2(Context context, String[] image1,String[] description) {
this.context = context;
this.image1 = image1;
this.description=description;
}
@OverridepublicbooleanisViewFromObject(View view, Objectobject) {
return view == ((LinearLayout) object);
}
@OverridepublicObjectinstantiateItem(ViewGroup container, int position) {
TextView des;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.slider, container,
false);
des = (TextView) itemView.findViewById(R.id.slider_des);
des.setText(description[position]);
AQuery aq = newAQuery(itemView);
aq.id(R.id.imageView1).image(image1[position], true, true, 0, 0, null, AQuery.FADE_IN, AQuery.RATIO_PRESERVE);
((ViewPager) container).removeView(itemView);
((ViewPager) container).addView(itemView);
return itemView;
}
@OverridepublicvoiddestroyItem(ViewGroup container, int position, Objectobject) {
((ViewPager) container).removeView((LinearLayout) object);
}
@Overridepublic int getCount() {
// TODO Auto-generated method stubreturn description.length;
}
}
this is an implementation of exactly what you want... now declare the variables for textview contents , declare the imageviews , bind em together... this should work...on your activity pass on the variables in the declared order to the adapter. the solution will work flawlessly. Ive used aquery to get image from url. you can simply pass on the image resource and bind it via imageview.setImageResource();
method
Solution 2:
instead of this line of code container.addView(imageView, 0);
write down ((VIewPager)container).addView(imageview, null);
this will add all the images of array provided above in one pager
for implementing three pagers
Step 1: Declare 3 viewpagers in xml and then in main activity
initialize each with new pager and set adapter as ImageAdapter object;
Solution 3:
create a view as per your requirement which will contain number of images and text you want.
in public Object instantiateItem(ViewGroup container, int position) inflate your that layout and add to view pager it will work perfectly.
Solution 4:
If your want detail Explanation and using ViewPagerIndicator
ViewPagerIndicator Dynamic Layout
I had done some research and found this solution for Dynamic layouts.
Question: Android: ViewPagerIndicator - Creating different layouts for different pages
Answer: https://stackoverflow.com/a/10696360/2236219
Performing click event for each layout
Using Gesture Listener:
Question: Touch or Click event ViewPagerIndicator in Android
Post a Comment for "Add Multiple Images And Text To Each Viewpager Slide"