android checkbox全选不全选单选
答案:2 悬赏:80 手机版
解决时间 2021-02-10 00:40
- 提问者网友:那叫心脏的地方装的都是你
- 2021-02-09 18:53
android checkbox全选不全选单选
最佳答案
- 五星知识达人网友:罪歌
- 2021-02-09 20:07
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.group_list2);
initBottomBar();
listView = (ListView) findViewById(R.id.groupListView);
GroupService service = new GroupService(this);
groupList = service.getGroupList(null);
adapter = new GroupListAdapter(this, groupList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> adapterView, View view, int position,
long arg3) {
// TODO Auto-generated method stub
Group group = groupList.get(position);
CheckBox ctb = (CheckBox) view.findViewById(R.id.checkBox);
ctb.toggle();
adapter.selectedMap.put(group.id, ctb.isChecked());
adapter.notifyDataSetChanged();
if(adapter.selectedMap.containsValue(true)){
add2ScanListBtn.setEnabled(true);
}else{
add2ScanListBtn.setEnabled(false);
}
}
});
}
private void initBottomBar(){
bottomBarView = (LinearLayout) findViewById(R.id.bottomBar);
add2ScanListBtn = (Button) bottomBarView.findViewById(R.id.add2ScanListBtn);
add2ScanListBtn.setEnabled(false);
checkBtn = (Button) bottomBarView.findViewById(R.id.checkBtn);
closeCheckBtn = (Button) bottomBarView.findViewById(R.id.closeCheckBtn);
add2ScanListBtn.setOnClickListener(this);
checkBtn.setOnClickListener(this);
closeCheckBtn.setOnClickListener(this);
}
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.group_list2);
initBottomBar();
listView = (ListView) findViewById(R.id.groupListView);
GroupService service = new GroupService(this);
groupList = service.getGroupList(null);
adapter = new GroupListAdapter(this, groupList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> adapterView, View view, int position,
long arg3) {
// TODO Auto-generated method stub
Group group = groupList.get(position);
CheckBox ctb = (CheckBox) view.findViewById(R.id.checkBox);
ctb.toggle();
adapter.selectedMap.put(group.id, ctb.isChecked());
adapter.notifyDataSetChanged();
if(adapter.selectedMap.containsValue(true)){
add2ScanListBtn.setEnabled(true);
}else{
add2ScanListBtn.setEnabled(false);
}
}
});
}
private void initBottomBar(){
bottomBarView = (LinearLayout) findViewById(R.id.bottomBar);
add2ScanListBtn = (Button) bottomBarView.findViewById(R.id.add2ScanListBtn);
add2ScanListBtn.setEnabled(false);
checkBtn = (Button) bottomBarView.findViewById(R.id.checkBtn);
closeCheckBtn = (Button) bottomBarView.findViewById(R.id.closeCheckBtn);
add2ScanListBtn.setOnClickListener(this);
checkBtn.setOnClickListener(this);
closeCheckBtn.setOnClickListener(this);
}
全部回答
- 1楼网友:拾荒鲤
- 2021-02-09 21:34
if(!checkbox.ischecked()){
checkbox.setchecked(true);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯