指定的孩子已经有一个父android

时间:2012-12-11 17:00:40

标签: android layout baseadapter

早上好!,我不知道,如何填写动态自定义基本适配器?,这是我的代码示例:

public class Row{
private Context context;
private CheckBox checkbox;
private String kind;

    public Row(Context context, String kind){
        this.context = context;
this.kind=kind;

    }

public start(){
  checkbox = new CheckBox(context);
}

public View getView(){
  View ch=getCheckbox();
  return ch;
}

public CheckBox getCheckbox(){
   return checkbox;
}

public String getKind(){
return kind;
}
}

public class Adapterd extends baseAdapter{
private Context context;
private ArrayList<Line> info;

  public Adapterd(Context context, ArrayList info){
 this.info=info;
 this.context=context;

 }

public View getView(int position, View convertView, ViewGroup parent) {
   View vi = convertView;

        inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if(info.get(position).getKind().equalsIgnoreCase("text")){
            vi = inflater.inflate(R.layout.adaptador_blank, null);
        }else{vi = inflater.inflate(R.layout.adaptador_checkbox, null);

checkLayout = (RelativeLayout) vi.findViewById(R.id.checkLayout);
checkLayout.addView(info.get(position).getCheckbox());
            }
   }
return vi;
}
}

public class Start{
private ListView content;

public void process(){
   ArrayList<Line> l = new ArrayList<Line>();
   l.add(new Line(this, "checkbox"));
  l.add(new Line(this, "text"));

  Adapterd adapt = new Adapterd(this, l);
content = (ListView) findViewById(R.id.layout2);
content.setAdapter(adapt);

}
}

有时当我添加大量复选框时,当它们位于屏幕视图下方时,值将被删除,字段正在切换并重复,我得到Specified child已经有一个父级:checkLayout.addView(info.get(位置).getCheckbox());我想。

我想在baseAdapter中管理多个不同的布局。

0 个答案:

没有答案