所以我到目前为止,请记住listView是动态的,因为它是从API调用的。
现在需要什么。
我尝试了什么:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder vh;
if(convertView == null){
vh = new ViewHolder();
convertView = mInflater.inflate(R.layout.projectlist_frame, null);
vh.projectTitle = (TextView)convertView.findViewById(R.id.projecttitle);
vh.projectSector = (TextView)convertView.findViewById(R.id.projectsector);
vh.cb = (CheckBox)convertView.findViewById(R.id.checkBox1);
convertView.setTag(vh);
} else{
vh = (ViewHolder)convertView.getTag();
}
vh.projectTitle.setText(mData.get(position).get("title").toString());
vh.projectSector.setText(mData.get(position).get("sector").toString());
vh.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
if(mMode==null){
mMode = startActionMode(mActionCallBack);
}
}
else{
if(mMode!=null){
mMode.finish();
}
}
}
});
return convertView;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return super.getViewTypeCount();
}
class ViewHolder{
TextView projectTitle, projectSector;
CheckBox cb;
}
}
适用于Contextuals ActionBar
private ActionMode.Callback mActionCallBack = new ActionMode.Callback() {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
for (int i = 0; i < list.getAdapter().getCount(); i++)
list.setItemChecked(i, false);
if (mode == mMode) {
mMode = null;
}
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.setTitle("Options");
mode.getMenuInflater().inflate(R.menu.contextual_menu_add_project, menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
long[] selected = list.getCheckedItemIds();
if (selected.length > 0) {
for (long id: selected) {
// Do something with the selected item
}
}
mode.finish();
return false;
}
};
有人可以帮我跟踪onCheck事件并使用上下文actionBar协调其操作。