问题描述
我已经从数据库获取日期自定义光标适配器和填充列表,它的 onlistItemClick 监听我显示连接至该行的观点,然后再次单击将隐藏视图,
一切工作正常,但我有两个问题,结果
1) - 我有10行,它表明10,但是当我登录的位置,它给我的只有那些位置,适合屏幕结果。
2) - 当我在一排点击,观点似乎是连接到该行,但是当我向下滚动,我发现另一种观点是可见按住屏幕,
i have a custom cursor adapter that fetches date from database and populate list , and its onlistItemClick listener i show a view attached to that row, and then hide that view by clicking it again,
everything is working fine, but i have two problems,
1)- i have 10 rows, it shows 10, but when i log positions, it gives me only those positions, that fits to screen.
2)- when i click on a row, view appears that is attached to that row, but when i scroll down, i found another view is visible down the screen,
这是我的适配器,
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;
}
}
我从小时的工作要弄清楚这个问题,但不成功..结果
请帮助任何照顾接受者。
I am working from hours to figure out the issue, but in vain..
Please help any care taker.
推荐答案
试着写getView方法来代替。
Try writing getView method instead.
例如:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = mInflater
.inflate(R.layout.list_layout, parent, false);
if (getCursor().getPosition() % 2 != 0) {
convertView.setBackgroundResource(R.drawable.list_selector);
}else{
convertView.setBackgroundResource(<-Something->);
}
return convertView;
}
修改
@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")));
if(cursor.getPosition()%2 != 0)
{
view.setBackgroundResource(R.drawable.list_selector);
}
}
这篇关于自定义光标适配器错位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!