Kekis2014 Kekis2014 - 4 months ago 32
Java Question

Is there any way to include a ViewPager in a listView to transition from one picture to another?

I'm currently making an application that is supposed to have a

listView
that contains a
textView
and under the
textView
it is supposed to have one
imageView
that contains many images, but that I can only see one image at a time. I want to be able to swipe on the
imageView
so that I can transition from one picture to another without having to leave the activity. Is there any way to include a
ViewPager
as seen in https://developer.android.com/training/animation/screen-slide.html but have it inside the
listView
or something similar in order to accomplish this? In case it is helpful I have included my custom adapter that currently only supports the text and one image.

public class MyAdapter extends BaseAdapter {
private Context mContext;
private List<Bean> mList;
private PopupWindow popUpWindow;
private LayoutInflater inflater;

public MyAdapter(Context context,List<Bean> list){
mContext=context;
mList=list;


}

@Override
public int getCount() {
return mList.size();
}

@Override
public Object getItem(int position) {
return mList.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
//use convertView recycle
if(convertView==null){
holder=new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.content_orders, parent, false);
holder.textView= (TextView) convertView.findViewById(R.id.textView2);
holder.imageView= (ImageView) convertView.findViewById(R.id.imageView2);
holder.information= (Button) convertView.findViewById(R.id.button5);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}

//set text and url
final View finalConvertView = convertView;
holder.information.setOnClickListener(new View.OnClickListener() {



@Override
public void onClick(View v) {
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup container = (ViewGroup) inflater.inflate(R.layout.information_popup, null);
popUpWindow = new PopupWindow(container, 800,400,true);
popUpWindow.showAtLocation(finalConvertView.findViewById(R.id.orders), Gravity.CENTER, 0,0);

container.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
popUpWindow.dismiss();
return true;
}
});
}
});

holder.textView.setText(mList.get(position).getText());
Picasso.with(mContext).load(mList.get(position).getUrl()).resize(500,500).into(holder.imageView);

return convertView;
}

class ViewHolder{
TextView textView;
ImageView imageView;
Button information;
Button close;

}
}

Answer

I ended up not being able to figure out how to do this using the viewPager, but I found out how to do it using a horizontalScrollView. Here is the link to the question with the answer that I posted.

Adding a Horizontal Scroll View to a ListView