我正在尝试向我的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个空白视图。

最佳答案

   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);
 }

关于java - 循环浏览不会产生正确的结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31900659/

10-09 15:59