如何使用volley在listview行中获取两个不同的图像

时间:2016-04-19 10:11:29

标签: android listview android-recyclerview material

我试图在一个列表中获取两个不同的图像 - 使用凌空查看行,但每次我在图像视图(网络图像视图)和i&#中都获得相同的图像39; m点击一个图像 - 查看其悬停的整行。 我是Android新手,编码请帮忙。

public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Movie> movieItems;
ImageLoader imageLoader = MyApplication.getInstance().getImageLoader();

public CustomListAdapter(Activity activity, List<Movie> movieItems) {
    this.activity = activity;
    this.movieItems = movieItems;
}

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

@Override
public Object getItem(int location) {
    return movieItems.get(location);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (inflater == null)
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null)
        convertView = inflater.inflate(R.layout.list_row, null);

    if (imageLoader == null)
        imageLoader = MyApplication.getInstance().getImageLoader();
    NetworkImageView thumbNail = (NetworkImageView) convertView
            .findViewById(R.id.thumbnail);
   NetworkImageView thumbNail2 = (NetworkImageView) convertView
            .findViewById(R.id.thumbnail2);

    // getting movie data for the row
    Movie m = movieItems.get(position);

    // thumbnail image
    thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);
    thumbNail2.setImageUrl(m.getThumbnailUrl(), imageLoader);

    // title
    return convertView;
}

}

list_row          

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:weightSum="2"
    android:layout_weight="1"
    android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">

        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/thumbnail"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp" />
            />





        <TextView
            android:elevation="6dp"
            android:id="@+id/category_title_one"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="20dp"
            android:layout_alignParentBottom="true"
            android:layout_margin="12dp"
            android:textColor="@android:color/white"
            />



    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">

        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/thumbnail2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_alignParentBottom="true" />




        <TextView
            android:elevation="6dp"
            android:id="@+id/category_title_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="20dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_margin="12dp"
            android:textColor="@android:color/white"
            />


    </RelativeLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

 thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);
 thumbNail2.setImageUrl(m.getThumbnailUrl(), imageLoader);

您可以注意到,您正在将相同的缩略图传递给两个图像视图。此外,您必须在一个位置加载两个Movie以显示两个图像。更好地使用GridView或甚至更好地使用{{1使用Recyclerview。如果要使用列表视图,请执行以下修改。

GridLayoutManager