분명히 내 생각에는 올바르게 작동하지 않으므로 몇 가지 결함이 있습니다. 기본적으로, 나는이 문제를 해결하기 위해 노력하고있어 : listview with checkboxListView는 태그를 사용하여 상태를 유지합니까?
답변에서, 사람들은 의미가있는 상태를 유지하기 위해 글로벌 데이터 구조를 만들 것을 제안했습니다. 그러나 ViewHolder 패턴을 사용하고 있다면 상태 정보를 저장하는 구조로 태그를 사용할 수 있다고 생각했습니다.
cbox.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
P tag = (P) ((View) v.getParent()).getTag();
if(tag.cbox.isChecked())
tag.cbox.setChecked(true);
else
tag.cbox.setChecked(false);
//tag.cbox.toggle();
Log.d("YoYo", Boolean.toString(tag.cbox.isChecked()));
}
});
위의 코드는 행에서 내 체크 박스를 전환하지 않았습니다. 나는 무엇을 잘못 했는가?
업데이트 : 토글 대신 수동 if 문이 작동하는 것 같습니다. 하지만, 다른 곳으로 스크롤 한 후 체크 상태가 엉망이되는 또 다른 문제가 있습니다. 왜 그런가요? tag.cbox에 체크 된 상태를 설정하면, 그 객체에 대해서만 유일한 체크 상태가 아닌가?
갱신 2 : 나는의 다른 제안을 따라 작업 버전을 가지고 있지만,의 SetTag/GetTag의 작동하지 않는 이유를 난 아직도 궁금하네요?
는 작동이 :
public View getView(final int position, View view, ViewGroup parent)
{
Plurker tag = getItem(position);
if (view == null)
view = adapterLayoutInflater.inflate(R.layout.adapter, null);
tag.avatar = (ImageView) view.findViewById(R.id.imgAvatar);
tag.cbox = (CheckBox) view.findViewById(R.id.cBox);
tag.cbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton btn, boolean isChecked)
{
int pos = position;
Plurker p = getItem(pos);
p.isChecked = isChecked;
Log.d("PLURK", "Listener:" + p.toString());
}
});
tag.update(getItem(position));
Log.d("PLURK", tag.cbox.getText() + ":" + Integer.toString(position));
return view;
}
작동하지 : 숨겨진에서보기를 다시 할 때 때문에 "작동하지 않는"버전에서
public View getView(final int position, View view, ViewGroup parent)
{
Plurker tag = getItem(position);
if (view == null)
{
view = adapterLayoutInflater.inflate(R.layout.adapter, null);
tag.avatar = (ImageView) view.findViewById(R.id.imgAvatar);
tag.cbox = (CheckBox) view.findViewById(R.id.cBox);
tag.cbox.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0)
{
int pos = position;
Plurker p = getItem(pos);
p.isChecked = !p.isChecked;
Log.d("PLURK", "Listener:" + p.toString());
}
});
view.setTag(tag);
}
else
tag = (Plurker) view.getTag();
tag.update(getItem(position));
Log.d("PLURK", tag.cbox.getText() + ":" + Integer.toString(position));
return view;
}
, 내가 대신 onCheckedChanged 이벤트의 온 클릭을 사용할 필요가 , 그것은 이벤트 리스너를 호출했기 때문에 잘못 트리거되었습니다.
링크의 내용에 따라 태그 대신 문자열 배열에 검사 상태를 저장해야합니다. 그것을 시도하고 잘하면 그게 당신을 위해 작동합니다. – maebe
@maebe 감사합니다! 하지만 그게 문제라고 생각하지 않습니다. 사실, 첫 번째 문제는 해결되었지만 지금은 또 다른 문제가 있습니다. S – Patrick
@Patrick 무엇을 찾고 있습니까? –