将数据填充到适配器类的列表视图(每个项目)中>
如果我在Activity中有代码// populate the data item.setText(megaItem.getName()); item.setChecked(megaItem.getStatus());
允许使用以下方式在“活动”中选择复选框:>
listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
问题:
问题#1。
use above line
,那么我在can check and uncheck all the items
中有list
,但是问题是,默认情况下,我是can't see some of my items as checked
,正如我提到的[ C0]的代码问题#2。如果我在Activity中的代码为status true
,则默认情况下为don't use above line
,因为我在代码中提到了它们的真实状态,但问题是,我can see some of my items as checked
在[can't check and uncheck any other item
Xml:
list
从适配器类获取getView()
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/checkedTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/CustomStyledRadioButton" android:drawableLeft="?android:attr/listChoiceIndicatorMultiple" />
将数据填充到Adapter类中的列表视图(每个项目)中//填充数据item.setText(megaItem.getName()); item.setChecked(megaItem.getStatus());允许多选复选框...
尝试一下。
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//get the data for the item at this position
MegaItem megaItem = getItem(position);
//check if the view is being reused, otherwise inflate it
if(convertView == null)
{
convertView = LayoutInflater.from(getContext()).inflate(R.layout.items_listview_layout,parent,false);
}
//get references to the UI elements to populate them
item = (CheckedTextView) convertView.findViewById(R.id.checkedTextView);
//populate the data
item.setText(megaItem.getItemName());
item.setChecked(megaItem.getStatus());
//return the view to render on the screen
return convertView;
}
在布局xml中为CheckedTextView设置一个checkMark属性