如何使用不同的文本和图像为多个相同的布局充气?我尝试使用此代码
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 和适配器,但我想了解是否可以在没有它们的情况下完成。