0

これは私のカスタムリストビューの行です。ご覧のとおり、3つのimageViewがあります。どうすればオーバーライドできますか

public View getView(int position, View convertView, ViewGroup parent)

リストにあるimageviewの数に関係なく、imageView.setImageResourceを設定できるように、アダプタークラスの どんな助けでも大歓迎です。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
<RelativeLayout
        android:id="@+id/LinearLayout01"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
<ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="10px" />
<ImageView
        android:id="@+id/image1"
        android:layout_toRightOf= "@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10px" />

<ImageView
        android:id="@+id/image2"
        android:layout_toRightOf= "@+id/image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10px" />
</RelativeLayout>
</LinearLayout>
4

1 に答える 1

2

アダプター内でホルダークラスを受講する

// View Holder for fast accessing List Row
private class ViewHolder {
    public ImageView image;
    public ImageView image1;
    public ImageView image2;
}

そしてgetViewメソッド

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = inflater.inflate(R.layout.row_layout,null);
                holder.image = (ImageView)convertView.findViewById(R.id.image);
                holder.image1 = (ImageView)convertView.findViewById(R.id.image1);
                holder.image2 = (ImageView)convertView.findViewById(R.id.image2);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            // Setting Image Resource here
            holder.image.setImageResource(R.drawable.icon);
            holder.image1.setImageResource(R.drawable.icon);
            holder.image2.setImageResource(R.drawable.icon);

            // return the listview row
            return convertView;
        }

ListViewの行レイアウトwhy you take LinearLayout and then RelativeLayout inside itでは、take RelativeLayout as a root node.

于 2012-07-27T10:56:52.263 に答える