使用自定义适配器后,ListView choiceMode是否被覆盖?

时间:2014-11-11 15:45:58

标签: android android-listview

我正在从自定义适配器类设置ListView。在我的布局中,我为choiceMode设置ListView

<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="multipleChoice"
android:cacheColorHint="#00000000" />  

然而,ListView上没有复选框。是因为现在使用自定义适配器覆盖了choiceMode行为吗?在这种情况下如何设置choiceMode

更新
以下是我的适配器代码:

public class ContanctAdapter extends ArrayAdapter<ContactBean> {

    private Activity activity;
    private List<ContactBean> items;
    private int row;
    private ContactBean objBean;

    public ContanctAdapter(Activity act, int row, List<ContactBean> items) {
        super(act, row, items);

        this.activity = act;
        this.row = row;
        this.items = items;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder;
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(row, null);

            holder = new ViewHolder();
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        if ((items == null) || ((position + 1) > items.size()))
            return view;

        objBean = items.get(position);

        holder.tvname = (TextView) view.findViewById(R.id.tvname);
        holder.tvPhoneNo = (TextView) view.findViewById(R.id.tvphone);

        if (holder.tvname != null && null != objBean.getName()
                && objBean.getName().trim().length() > 0) {
            holder.tvname.setText(Html.fromHtml(objBean.getName()));
        }
        if (holder.tvPhoneNo != null && null != objBean.getPhoneNo()
                && objBean.getPhoneNo().trim().length() > 0) {
            holder.tvPhoneNo.setText(Html.fromHtml(objBean.getPhoneNo()));
        }
        return view;
    }

    public class ViewHolder {
        public TextView tvname, tvPhoneNo;
    }

}

1 个答案:

答案 0 :(得分:0)

检查自定义适配器的 createViewFromResource 方法,可能存在问题。无论如何,如果您发布您的适配器代码(虽然标准的UI部分),您可以获得更多帮助