【发布时间】:2013-11-29 05:29:12
【问题描述】:
我有一个自定义光标适配器,它从数据库中获取日期并填充列表,它的 onlistItemClick 侦听器我显示了一个附加到该行的视图,然后通过再次单击它来隐藏该视图,
一切正常,但我有两个问题,
1)- 我有 10 行,它显示 10,但是当我记录位置时,它只给我那些适合屏幕的位置。
2)- 当我单击一行时,会出现附加到该行的视图,但是当我向下滚动时,我发现屏幕下方可以看到另一个视图,
这是我的适配器,
public class CustomCursorAdapter extends CursorAdapter {
private LayoutInflater mInflater;
public CustomCursorAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
mInflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, final Context context, final Cursor cursor) {
TextView textView = (TextView) view.findViewById(R.id.txtview);
textView.setText(cursor.getString(cursor.getColumnIndex("text")));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
//in that "list_layout.xml" i made a view that has to show and hide on click listener
View rowView = mInflater.inflate(R.layout.list_layout, parent, false);
if(cursor.getPosition()%2 != 0)
{
rowView.setBackgroundResource(R.drawable.list_selector);
}
return rowView;
}
}
我一直在努力解决问题,但徒劳无功..
请帮助任何看护人。
【问题讨论】:
-
抱歉,我无法理解您的第二期。您能详细说明一下吗?
-
它适用于我已经说过的适合屏幕的行,但是当我向下滚动时,日志不会给出新的位置,例如,如果屏幕上出现 5 条记录,它将给出 0-4当我向下滚动时,它又从 0 开始..
-
你真正想要完成什么?
-
你在哪里记录这些行号?
-
在新的视图方法中,int position = cursor.getPosition(); Log.d("位置", "" + 位置);
标签: android android-cursoradapter