Android

뷰페이저

Machine_웅 2018. 5. 10. 11:22
728x90
반응형
// 뷰페이저 세팅
viewPager = (ViewPager) findViewById(R.id.show_Add_Ask_Help_ViewPager);
imageSliderAdapter = new showMyAskHelpSliderAdater(this, images,images.size());
viewPager.setAdapter(imageSliderAdapter);

<onCreate>

 

 

 

 

 

 


public class showMyAskHelpSliderAdater extends PagerAdapter {

// 넘어와야할 데이터들
public LayoutInflater inflater;
public Context context;
public ArrayList<String> images = new ArrayList<>();
public String a;

public int count;

//생성자
public showMyAskHelpSliderAdater (Context context,ArrayList<String> images,int count){
this.context = context;
this.images = images;
this.count =count;
}

@Override
public int getCount() {
// 이미지들의 갯수
return count;
}

@Override
public boolean isViewFromObject(View view, Object object) {
// 안되면 view == ((View)object); 로 수정
return view == object;
}


@Override
public Object instantiateItem(ViewGroup container, int position) {
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.show_my_ask_help_image_slider,container,false);
ImageView sliderImage = (ImageView)v.findViewById(R.id.show_My_Ask_Help_Slider);

// 글라이더 사용 부분 ( 포지션에 따라서 달라지도록 )
//Glide.with(context).load(images.get(position)).into(sliderImage);
final String a = ""+images.get(position);
Glide.with(context).load(a).into(sliderImage);

return v;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.invalidate();
}
}

<adapter>

 

 

 

 

 

 

<item Layout>   show_my_ask_help_image_slider

728x90
반응형