每第9行都会被检查

时间:2012-06-19 20:59:10

标签: android list checkbox backup row

iam正在开发一个应用程序备份应用程序,我想这样做它只备份我通过复选框选择的那些应用程序。我已经在列表中实现了复选框,但是当我在每个第9行检查一行之前和之后它也会被检查:S

PS。我也很感激,如果有人可以帮助我,我可以如何制作,以便应用备份也可以工作:)

(这只是完整java文件的一小部分)

private static class AppViewHolder {
    TextView top_view;
    TextView bottom_view;
    ImageView icon;
    CheckBox check_mark;
    //@SuppressWarnings("unused")
}

private class TableView extends ArrayAdapter<ApplicationInfo> {

    private TableView() {
        super(main.this, R.layout.tablerow_02, mAppList);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        AppViewHolder holder;
        ApplicationInfo info = mAppList.get(position);

        if(convertView == null) {
            LayoutInflater inflater = getLayoutInflater();
            convertView = inflater.inflate(R.layout.tablerow_02, parent, false);

            holder = new AppViewHolder();
            holder.top_view = (TextView)convertView.findViewById(R.id.top_view);
            holder.bottom_view = (TextView)convertView.findViewById(R.id.bottom_view);

            holder.check_mark = (CheckBox)convertView.findViewById(R.id.checkBox1);


            holder.icon = (ImageView)convertView.findViewById(R.id.row_image);
            holder.icon.setMaxHeight(40);
            convertView.setTag(holder);

        } else {
            holder = (AppViewHolder) convertView.getTag();
        }

        holder.check_mark.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                if ( isChecked )
                {
                    Toast.makeText(getApplicationContext(), "#" + position + " is checked", Toast.LENGTH_LONG).show();
                }
                else{
                    Toast.makeText(getApplicationContext(), "#" + position + " is unchecked", Toast.LENGTH_LONG).show();
                }

            }
        });

        holder.top_view.setText(info.loadLabel(getPackageManager()));
        holder.bottom_view.setText(info.packageName);

        //this should not throw the exception
        try {
            holder.icon.setImageDrawable(mPackMag.getApplicationIcon(info.packageName));
        } catch (NameNotFoundException e) {
            holder.icon.setImageResource(R.drawable.ic_launcher);
        }

        return convertView;
    }

}

1 个答案:

答案 0 :(得分:3)

因为你没有正确回收意见。您应该保留一组布尔值,列表中的每个项目都有一个布尔值。然后在getView中,您需要根据该布尔值列表中的值在setChecked上调用holder.check_mark