0

我正在使用 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());
4

1 回答 1

0

添加下面的行。

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

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

将 mListView 替换为您的 Listview 对象名称。

于 2013-12-27T11:49:36.343 回答