在我的Android应用程序的一部分,我有一个ListView
显示表中的条目列表。当用户点击ListView
项目时,会显示此项目的新Intent
。ListView与自定义CursorAdapter不能很好地工作
在新的意向用户可以在此项目做一些操作如阅读,编辑,加入最爱(和unfavoriting当项目已收藏)。在详细意图变更在其表中的条目的“标记”栏中当它是收藏并当unfavorited。
它工作正常。但问题出在我的主人ListView
。我为我的ListView
设置了一个自定义CursorAdapter
。我想添加ImageView
,表明天气条目是收藏或不。在我的ListView
项目的布局文件中,我为此添加了一个ImageView
并将其visibility
设置为GONE
。
我想检测收藏项目并将其明星ImageView
visibility
设置为VISIBLE
。然后我在我的设备中运行应用程序。像往常一样,没有任何条目是受欢迎的。然后点击ListView
中的第一个项目,打开该项目的详细信息页面。我收藏它,并回到名单。好吧,现在第一个项目上有一个星形图标,但不仅在这个上,还有其他一些项目。这些错误加星标项目的详细信息页面表示它不是收藏。所以问题不在于我的数据库操作。我也检查显示标记项目的光标,其.getCount()
也表示只有项目收藏。我找不到问题所在。我写我的简化源代码定制CursorAdapter
波纹管:
public class HereIsMyAdapter extends CursorAdapter {
private final LayoutInflater mInflater;
public HereIsMyAdapter(Context context, Cursor cursor) {
super(context, cursor, true);
mInflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView txtTestText = (TextView) view.findViewById(R.id.txtTestText);
ImageView imgMark = (ImageView) view.findViewById(R.id.imgMark);
txtSureAz.setText(cursor.getString(cursor.getColumnIndex("azname")));
boolean isMarked = cursor.getInt(cursor.getColumnIndex("marked")) == 1 ? true : false;
if (isMarked) {
imgMark.setVisibility(0);
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = mInflater.inflate(R.layout.my_list_item, parent, false);
bindView(view, context, cursor);
return view;
}
}
好主意,但没有工作:(仍有不希望的痕迹。而在不同的项目时重新开启应用程式 – 2012-02-16 18:40:36
很抱歉,但我才意识到,为什么你在NewView的方法调用bindView() ? – juanmhidalgo 2012-02-16 18:45:52
我在一个自定义的CursorAdapter教程中看到它后,我在调用这个方法的时候调用了这个方法,但是结果和我一样,即使我删除了这一行 – 2012-02-16 18:52:03