循环浏览并不会产生正确的结果

时间:2015-08-09 03:40:36

标签: java android

我正在尝试向LinearLayout添加一堆视图。

for (Business b : businesses) {
  View view = getLayoutInflater().inflate(R.layout.card_item, mLinearLayout, true);

  ImageView mImageView = (ImageView) view.findViewById(R.id.image);

  Picasso.with(getBaseContext())
            .load(b.getPhotoUrl())
            .into(mImageView);

  TextView mTextView = (TextView) view.findViewById(R.id.title);
  mTextView.setText(b.getName());
}

然而,它显示1张信息卡。然后是19个空白视图。

1 个答案:

答案 0 :(得分:1)

   for (Business b : businesses) {
   View view = getLayoutInflater().inflate(R.layout.card_item, mLinearLayout, false);

   ImageView mImageView = (ImageView) view.findViewById(R.id.image);

  Picasso.with(getBaseContext())
        .load(b.getPhotoUrl())
        .into(mImageView);

 TextView mTextView = (TextView) view.findViewById(R.id.title);
 mTextView.setText(b.getName());

 mLinearLayout.addView(view);
 }