public class ListString {
String _title;
boolean _check = false;
public ListString(String title, boolean check) {
this._title = title;
this._check = check;
}
public String getTitle() {
return _title;
}
public void setTitle(String title) {
this._title = title;
}
public boolean ismCheck() {
return _check;
}
public void setmCheck(boolean check) {
this._check = check;
}
}
=====================================
public class ListViewAdapter extends BaseAdapter{
private Context _context;
private List<ListString> _itemList;
private int _layout;
ViewHolder holder;
private boolean checking;
public ListViewAdapter(Context context, int layout, List<ListString> itemList){
this._context = context;
this._layout = layout;
this._itemList = itemList;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return _itemList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return _itemList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return _itemList.indexOf(getItem(position));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater vi = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(convertView == null){
convertView = vi.inflate(_layout, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.code);
holder.chb = (CheckBox) convertView.findViewById(R.id.checkBox1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ListString rowItem = (ListString) getItem(position);
holder.title.setText(rowItem.getTitle());
holder.chb.setText(null);
holder.chb.setChecked(false);
holder.chb.setChecked(rowItem.ismCheck());
// holder.chb.setTag(rowItem);
// holder.chb.setChecked(((ListView)parent).isItemChecked(position));
return convertView;
}
}
어떻게 설명을 해야 될지... 일단 위와 같이 각각의 소스를 해보았습니다.
일단 하고자 하는 것은 listView를 클릭을 하면 체크박스가 체크가 되고 다지 않고를 하려고 합니다.
리스트뷰가 있는 class 에 onItemClick 부분에
ListString list = (ListString) parent.getItemAtPosition(position);
if(list.ismCheck() == false){
list.setmCheck(true);
} else {
list.setmCheck(false);
}
이런 구문을 넣었습니다... 하지만 제대로 되지 않더군요....생각나는 방법을 모두 동원 해보았지만...
어떠한 방법을 하는 것이 좋은지...부탁 드립니다 ㅜㅜ