CheckedTextView无法检查项目

时间:2013-12-27 11:34:28

标签: android listview checkedtextview

我正在使用CheckedTextView处理列表视图,

以下是我的代码:

RelativeLayout parentMostLayout = new RelativeLayout(activity);
    parentMostLayout.setLayoutParams(new AbsListView.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
        RelativeLayout.LayoutParams.WRAP_CONTENT));

CheckedTextView checkedTextView = new CheckedTextView(activity);
int[] attrs = { android.R.attr.listChoiceIndicatorMultiple };
    TypedArray ta = activity.getTheme().obtainStyledAttributes(attrs);
    Drawable indicator = ta.getDrawable(0);
    checkedTextView.setCheckMarkDrawable(indicator);
    ta.recycle();
parentMostLayout.addView(checkedTextView, checkedTextViewlLayoutParams);

当我尝试检查该项目时,它没有标记我要选择的项目,这可能是什么问题?

修改

ListView listView = new ListView(activity);
listView.setCacheColorHint(Color.TRANSPARENT);
    listView.setDivider(new ColorDrawable(0x99000000));
    listView.setDividerHeight(1);
listView.setSelector(R.drawable.listselector);
RelativeLayout.LayoutParams listViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
        RelativeLayout.LayoutParams.MATCH_PARENT);
listViewParams.addRule(RelativeLayout.ABOVE, footerBar.getId());

1 个答案:

答案 0 :(得分:0)

添加以下行。

//  for single check
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

// for multiple check
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

将mListView替换为Listview对象名称。