2015-08-09 41 views
0

我想添加一堆視圖到我的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
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); 
}