Tôi có một ListView trong đó sử dụng một bộ chuyển đổi tùy chỉnh như:listview với adapter tùy chỉnh chứa CheckBoxesfunction
private class CBAdapter extends BaseAdapter implements OnCheckedChangeListener{
Context context;
public String[] englishNames;
LayoutInflater inflater;
CheckBox[] checkBoxArray;
LinearLayout[] viewArray;
private boolean[] checked;
public CBAdapter(Context con, String[] engNames){
context=con;
englishNames=engNames;
inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
checked= new boolean[englishNames.length];
for(int i=0; i<checked.length; i++){
checked[i]=false;
//Toast.makeText(con, checked.toString(),Toast.LENGTH_SHORT).show();
}
checkBoxArray = new CheckBox[checked.length];
viewArray = new LinearLayout[checked.length];
}
public int getCount() {
return englishNames.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
if(viewArray[position] == null){
viewArray[position]=(LinearLayout)inflater.inflate(R.layout.record_view_start,null);
TextView tv=(TextView)viewArray[position].findViewById(R.id.engName);
tv.setText(englishNames[position]);
checkBoxArray[position]=(CheckBox)viewArray[position].findViewById(R.id.checkBox1);
}
checkBoxArray[position].setChecked(checked[position]);
checkBoxArray[position].setOnCheckedChangeListener(this);
return viewArray[position];
}
public void checkAll(boolean areChecked){
for(int i=0; i<checked.length; i++){
checked[i]=areChecked;
if(checkBoxArray[i] != null)
checkBoxArray[i].setChecked(areChecked);
}
notifyDataSetChanged();
}
public void onCheckedChanged(CompoundButton cb, boolean isChecked) {
for(int i=0; i<checked.length; i++){
if(cb == checkBoxArray[i])
checked[i]=isChecked;
}
}
public boolean itemIsChecked(int i){
return checked[i];
}
}
Sơ đồ bố trí khá đơn giản vì vậy tôi sẽ không gửi cho họ trừ khi có ai nghĩ họ có liên quan.
Vấn đề là một số hộp kiểm tra không phản hồi. Nó có vẻ là những người có thể nhìn thấy khi bố trí được hiển thị đầu tiên. Bất kỳ thứ gì bạn phải cuộn xuống để hoạt động như mong đợi.
Bất kỳ con trỏ nào được đánh giá cao.
Làm thế nào để bạn làm điều này cho một hộp kiểm EcxpandableListView với con? – RicNjesh
@RicNjesh Bạn sẽ muốn sử dụng phương thức 'getChildView()' được gọi bất cứ khi nào một hàng con là bắt buộc. – Luksprog
những gì được kiểm tra trong trường hợp này và làm thế nào để khai báo nó? –