android向linearlayout添加多个View 怎么只显示最开始的一个View

public class HaigouAdapter extends BaseAdapter {
HomeActivity homeActivity;
private List list;
LayoutInflater inflater;

public HaigouAdapter(HomeActivity homeActivity, List list) {
    this.homeActivity = homeActivity;
    this.list = list;
    inflater = (LayoutInflater) homeActivity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return list.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return list.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = inflater
                .inflate(R.layout.haigou_list_item, null);
        holder = new ViewHolder();
        holder.gf_name = (TextView) convertView.findViewById(R.id.gf_name);
        holder.suits = (LinearLayout) convertView
                .findViewById(R.id.suits2);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }


    final Map map = (Map)list.get(position);
    holder.gf_name.setText(map.get("gf_name").toString());

    final List<Map<String, Object>> goods_list = (List<Map<String, Object>>) map.get("goods_list");

    holder.suits.removeAllViews();
    for (Map suit : goods_list) {
        View view = inflater.inflate(R.layout.haigo_list_lb, null);
        ImageView img = (ImageView) view.findViewById(R.id.haigoimg5);
        homeActivity.displayImage(suit.get("goods_main_photo").toString(), img);
        TextView name = (TextView) view.findViewById(R.id.haigoname);
        name.setText(suit.get("goods_name").toString());
        TextView price = (TextView) view.findViewById(R.id.haigoprice);

        price.setText("¥" +suit.get("goods_current_price").toString());
        final String goods_id = suit.get("goods_id").toString();
        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                homeActivity.go_goods(goods_id);
            }
        });


        holder.suits.addView(view);

    }
    return convertView;
}

public static class ViewHolder {
    public ImageView img;
    public TextView userlevel_3;
    public TextView userlevel_2;
    public TextView userlevel_1;
    public TextView gf_name;
    public TextView goods_name;
    public TextView lowest_price;
    public TextView sale_count;
    public LinearLayout suits;
}

}

3个回答

你只发适配器代码,怎么解决?其他类文件,布局文件,代码也发来才好解决。。。。

是不是你布局设置的match

已解决,添加了
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
holder.suits.setLayoutParams(lp);//设置布局参数
holder.suits.setOrientation(LinearLayout.VERTICAL);// 设置子View的Linearlayout// 为水平方向布局

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐