I currently have an adapter that takes two images and a text view to add to a listView
. I want to change this so that I can add a horizontalScrollView
inside each list item that contains the images. Would there be any way to do this?
This my current working adapter as described above with two imageView
's and a textView
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.imageView2 = (ImageView) convertView.findViewById(R.id.imageView3);
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(450,450).into(holder.imageView);
Picasso.with(mContext).load(mList.get(position).getUrl2()).resize(450,450).into(holder.imageView2);
return convertView;
}
class ViewHolder{
TextView textView;
ImageView imageView;
ImageView imageView2;
Button information;
}
}
Getter and Setter Class
public class Bean {
String text;
String url;
String url2;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl2() {
return url2;
}
public void setUrl2(String url2) {
this.url2 = url2;
}
}
Activity Layout XML
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".OrdersActivity"
android:background="#ffffff">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/orderListView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:dividerHeight="2dp"/>
</android.support.design.widget.CoordinatorLayout>
Content Layout XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".OrdersActivity"
android:id="@+id/orders">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imageView2"
android:src="@drawable/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/one"
android:id="@+id/imageView3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/imageView2"
android:layout_alignTop="@+id/imageView2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/informaci_n"
android:id="@+id/button5"
android:layout_below="@+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/entregado"
android:id="@+id/button3"
android:layout_below="@+id/imageView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_entregado"
android:id="@+id/button4"
android:layout_below="@+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>