我的ListActivity有什么问题?

时间:2011-10-12 21:57:34

标签: android listactivity android-arrayadapter

我创建了一个扩展arrayAdapter的ListActivity;列表的每个元素由2个标签和1个复选框组成。它工作得非常好,除非我取消选中其中一个列表框并向上或向下滚动,使此检查不可用;问题是,当我回到之前未取消选中的复选框时,它会被检查...我的listActivity出了什么问题?这是基于ArrayAdapter的类:

private class DescrAdapter extends ArrayAdapter<StatDescriptor>{
    private LayoutInflater  inflater;
    private final StatDescriptor[] descriptions;
    private int layoutId;


    public DescrAdapter(Context context, int res,StatDescriptor[] objects) {
        super(context,res , objects);
        this.inflater=LayoutInflater.from(context);
        this.descriptions=objects;
        this.layoutId=res;
    }

    public View getView(final int position, View rowView, ViewGroup parent) {
        rowView = (RelativeLayout) inflater.inflate(layoutId, null);
        TextView textName = (TextView) rowView.findViewById(R.id.StatName);
        textName.setText(descriptions[position].getName());
        TextView textDescr=(TextView) rowView.findViewById(R.id.StatDescr);
        textDescr.setText(descriptions[position].getDescription());
        CheckBox checkEnabled=(CheckBox) rowView.findViewById(R.id.checkStat);
        checkEnabled.setChecked(descriptions[position].isEnabled());
        checkEnabled.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                enabledStats[sortIndexes[position]]=!enabledStats[sortIndexes[position]];
            }
        });
        return rowView;
    }

}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您使用descriptions[position]设置复选框的状态,但是您可以翻转enabledStats[sortIndexes[position]]。因此,下次使用您未更改的原始值重新创建项目视图时(descriptions[position])。

相关问题