我使用自定义适配器,它扩展了SimpleCursorAdadapter。列表视图中的所有项目都可以在屏幕上看到所有工作正常,但如果项目数量超过屏幕中可以包含的项目位置重复(例如我点击第一项,第一项隐藏项目也被激活)
public class CustomAdapter extends SimpleCursorAdapter {
private Context mContext;
private Context appContext;
private int layout;
private Cursor cursor;
private final LayoutInflater inflater;
DB db;
public CustomAdapter(Context context, int layout, Cursor c,String[] from,int[] to) {
super(context,layout,c,from,to);
this.layout=layout;
this.mContext = context;
this.inflater=LayoutInflater.from(context);
this.cursor=c;
}
@Override
public View newView (Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(layout, null);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
ImageView marker = (ImageView)view.findViewById(R.id.item_productiviry_img);
TextView prod_tv = (TextView)view.findViewById(R.id.tvMarker);
if(prod_tv.getText().length() == 10)marker.setImageResource(R.drawable.productive);
if(prod_tv.getText().length() == 7)marker.setImageResource(R.drawable.neutral);
if(prod_tv.getText().length() == 12)marker.setImageResource(R.drawable.unproductive);
}
}