清单不公开;无法从外部包

时间:2018-04-24 09:09:46

标签: java android

这是我的名为.... CheckListAdapter的适配器,在这里我只从数据库中获取数据并在listview中显示...之后我在这里只从listview获取检查项目但是我也无法理解。

public class CheckListAdapter extends BaseAdapter {
    private Context mContext;
    ViewHolder holder;
    ArrayList<CheckList_Items> arrEmps;
    public CheckListAdapter(Context c, ArrayList<CheckList_Items> map) {
        mContext = c;
        arrEmps = map;
    }
    @Override
    public int getViewTypeCount() {
        return getCount();
    }
    public int getItemViewType(int position) {
        return position;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return arrEmps.size();
    }
    @Override
    public Object getItem(int position) {

        return arrEmps.get(position);
    }
    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View grid = convertView;
        if (convertView == null) {
            holder = new ViewHolder();
            grid = inflater.inflate(R.layout.checklist, null);
            grid.setMinimumHeight(150);
            holder.name = (TextView) grid.findViewById(R.id.t1);
            holder.box = (CheckBox) grid.findViewById(R.id.checkBox);
            grid.setTag(holder);
        } else {
            holder = (ViewHolder) grid.getTag();
        }
        CheckList_Items p = getCheckList_Items(position);
        holder.name.setText(arrEmps.get(position).getName());
        holder.box.setOnCheckedChangeListener(myCheckChangeList);
        holder.box.setTag(position);
        holder.box.setChecked(p.getChecked());
        return grid;
    }
    CheckList_Items getCheckList_Items(int position) {
        return ((CheckList_Items) getItem(position));
    }
    ArrayList<CheckListAdapter> getBox() {
        ArrayList<CheckListAdapter> checked = new ArrayList<CheckListAdapter>();
        for (CheckList_Items p : arrEmps) {
            if (p.getChecked())
                checked.add(p);
        }
        return checked;
    }
    CompoundButton.OnCheckedChangeListener myCheckChangeList = new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,
                                     boolean isChecked) {
            getCheckList_Items((Integer) buttonView.getTag()).checked = isChecked;
        }
    };
    class ViewHolder {
        TextView name;
        CheckBox box;
    }
}

这是名为CheckList_Items

的类
public class CheckList_Items {
    boolean checked;
    String name;
    public CheckList_Items(String name) {
      //  this.empID = empID;
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public boolean getChecked() {
        return checked;
    }
    public void setSelected(boolean check) {
        checked = check;
    }
}

我遇到了这些行中的错误......我改变了很多类型,但我不能让输出只得到错误

   getCheckList_Items((Integer) buttonView.getTag()).checked = isChecked;

错误:在CheckList_Items中检查不公开;无法从外包装

访问
            checked.add(p);

错误:找不到合适的添加方法(CheckList_Items)                 checked.add(P);

有人帮我这个...... 感谢..

2 个答案:

答案 0 :(得分:1)

public

前添加getCheckList_Items

现在它是包私有

答案 1 :(得分:0)

您正尝试将类型为CheckList_Items的项目添加到CheckListAdapter列表中,替换:

ArrayList<CheckListAdapter> getBox() {
        ArrayList<CheckListAdapter> checked = new ArrayList<CheckListAdapter>();
        for (CheckList_Items p : arrEmps) {
            if (p.getChecked())
                checked.add(p);
        }
        return checked;
    }

with:

ArrayList<CheckList_Items> getBox() {
    ArrayList<CheckList_Items> checked = new ArrayList<CheckList_Items>();
    for (CheckList_Items p : arrEmps) {
        if (p.getChecked())
            checked.add(p);
    }
    return checked;
}