0

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

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

}
}

有时当我添加很多复选框时,当它们位于屏幕视图下方时,值被删除,字段正在切换和重复,我得到指定的孩子已经有一个父级:checkLayout.addView(info.get(position). getCheckbox()); 我猜。

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

4

0 回答 0