我有一个自定义ListView
点击一个项目触发一个新的Activity
。 ListView
的每一行都有一个CheckBox
和一个TextView
。可以调用onCheckedChanged方法而不进行交互吗?
这是getView
方法从我的自定义ListView
:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.puzzles_row, null);
}
ListedPuzzle lp = items.get(position);
if (lp != null) {
TextView title = (TextView) v.findViewById(R.id.listTitles);
title.setText(lp.getTitle());
CheckBox star = (CheckBox) v.findViewById(R.id.star_listed);
star.setChecked(lp.isStarred());
star.setTag(new Integer(position));
star.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Integer realPosition = (Integer) buttonView.getTag();
ListedPuzzle obj = items.get(realPosition);
starListedPuzzle(obj.getId(), isChecked);
}
});
}
return v;
}
的onCheckedChanged
到来时从另一个Activty回来,没有可能的用户交互来实际检查任何被调用。
问题是过去工作正常,没有真正改变任何事情。我有read这是一个错误,但不能真正相信它。
它始终调用ListView
的相同两项中的方法。莫名其妙地设置为checkedChange=true
?
你是绝对正确的!但是,现在,点击我的CheckBox并没有做任何事情。 – eskalera
它应该在'super.onRestoreInstanceState'完成执行后将'mRestoringInstanceState'设置回'false'。 –
此外,您还可以将'star.setOnCheckedChangeListener ...'行移至'onResume'方法,因为这会在'onRestoreInstanceState'后调用。在这种情况下,你不需要实现'onRestoreInstanceState'。我将编辑我的答案以显示此选项。 –