0

複数の同じレイアウトを異なるテキストと画像で膨らませるにはどうすればよいですか? このコードを使用してみました

    for (final Tour t : info.tours) {
        final LinearLayout list = (LinearLayout) findViewById(R.id.tours_list);
        Log.d(Const.LOG_TAG, "Add child view to tours_list");
        final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View child = inflater.inflate(R.layout.tour_item_for_guide_info,
                list, true);
        final ImageView tourImage = (ImageView) findViewById(R.id.tour_image);
        final String tourImgUrl = Const.HOST + t.image;
        imageLoader.DisplayImage(tourImgUrl, tourImage);
        TextView tourText = (TextView) findViewById(R.id.text);
        tourText.setText(t.name);
    }

ただし、テキストと画像は最初に膨張したレイアウトに設定され、以前のテキストと画像が置き換えられます。レイアウトのIDが同じであるため、何が起こるか理解しています。解決できますか?ListView とアダプターについては知っていますが、それらがなくてもできるかどうかを知りたいです。

4

1 に答える 1

2

ImageViewとTextView- tourImagetourText-はの要素であると思いR.layout.tour_item_for_guide_infoます。

その場合は、それを参照するときに、childビューを使用してそれらを取得する必要があります。

言い換えれば、代わりに:

ImageView tourImage = (ImageView) findViewById(R.id.tour_image);
TextView tourText = (TextView) findViewById(R.id.text);

あなたが持っている必要があります:

ImageView tourImage = (ImageView)child.findViewById(R.id.tour_image);
TextView tourText = (TextView)child.findViewById(R.id.text);

これで問題が確実に解決するかどうかはわかりませんが、バグのようです。

于 2012-09-18T14:42:44.957 に答える