private class ContactsListAdapter<T extends Contact> extends ArrayAdapter<T> {
private List<T> contactsList;
private String[] checkState;
private CheckBox cBox;
private View view;
public ContactsListAdapter(Context context, int textViewResourceId,List<T> items) {
super(context, textViewResourceId, items);
contactsList = items;
checkState = new String[totalListNum];
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
this.view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.contacts_list_row, null);
}
T contacts = contactsList.get(position);
if (contacts != null) {
TextView viewName = (TextView) view.findViewById(R.id.toptext);
if (viewName != null) {
viewName.setText(contacts.getName());
}
TextView viewNumber = (TextView) view.findViewById(R.id.bottomtext);
if (viewNumber != null) {
viewNumber.setText(contacts.getNumber());
}
cBox = (CheckBox) findViewById(R.id.CheckBox01);
if (cBox != null) {
if( cBox.isChecked() ){
checkState[position] = "1";
Log.d("checked","1");
}else{
checkState[position] = "0";
Log.d("checked","0");
}
if("0".equals(checkState[position])) {
Log.d("checked","false");
cBox.setChecked(false);
}else {
Log.d("checked","true");
cBox.setChecked(true);
}
Log.d("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "" + "Checked... : " + contacts.get_id() + " , " + contacts.getListPosition());
}
}
return view;
}
}
리스트는 쭈~욱 잘 찍히고 스크롤도 되는데.... 문제는 리스트마다 있는 체크박스 컨트롤이 잘 안되네요...
다른분들도 비슷한 문제로 밤 샜다고 하시던데, getview 안에서 체크박스 처리는 안되는건가여 ;;;
getview에서 포지션을 찎어보니 화면에 찍히는 리스트의 갯수인 0~7까지 찍히고 스크롤시 위 아래로 튀어나오는
새로운 리스트에 대한 포지션이 추가가 되더군요...
getview내에서 처리하는 방법좀 알려주세용 ㅠㅜ
^^
풀소스 안에서 쓰는(그 체크달린 리스트) 방법은 일단 CheckedTextView라는 넘을 씁니다.
이넘의 특징은 Checkable을 implement합니다.
여기서 중요한 점은 Checkable을 implement한다는 점하고 여기에 달려있는 체크박스가...
우리가 알고 있는 체크박스 컨트롤이 아니라는 점입니다.
엄밀히 말하믄 우리가 말하는 체크박스와 가장 유사한 것은 CheckedTextView 자체가 되겠습니다.
CheckedTextView를 보면 자신의 state(check가 true냐 false냐)에 따라서 Check이미지를 그리고 있습니다.
그렇다면 이걸 응용하면 간단하게 해결 할 수 있습니다.
LinearLayout 상속 받고 Checkable implement 해서
체크 올때 마다 if문 보고 ImageView에 체크모양 그려주면 됩니다.
기본 ListView에서 Multiselect 하는것처럼 똑같이 쓸수 있습니다.