我想研究android sqlite,所以我创建了一个即时标记应用程序,用户可以在其中标记他的照片并将它们上传到他的网络(google+、fb、twitter)问题是我有一个ListFragment
用户可以看到他所做的所有标记,列表中的图像元素存储在隐藏文件夹中,单词存储在 sqlite db 中。问题是在向上或向下滚动时,某些项目只是随机切换,即使我有超过 8 个项目,它们第 8 个项目是重复显示(即 1-8 而不是 9-12 我再次看到 1-4)唯一的问题可能出在适配器中,但是在调试会话的会话之后我找不到问题我的适配器代码是 -
public class FlowAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, List<String>>> data;
private static LayoutInflater layoutInflater = null;
public FlowAdapter(Activity activityContext,
ArrayList<HashMap<String, List<String>>> data) {
this.activity = activityContext;
this.data = data;
this.layoutInflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return data.get(position);
}
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// method variables
ViewHolder cacheView;
HashMap<String, List<String>> photos = null;
photos = data.get(position);
ImageView iv;
FlowLayout flow;
ArrayList<String> subjects = new ArrayList<String>();
if (convertView == null) {
cacheView = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.list_item, null);
flow = (FlowLayout) convertView.findViewById(R.id.flow_tags);;
// add the tags to the flowlayout
int size = photos.get(DatabaseHandler.KEY_TAGS).size();
for (int i = 0; i < size; i++) {
String name = String.format("#%s",
photos.get(DatabaseHandler.KEY_TAGS).get(i));
Bubble.getBubble(name, flow, subjects, activity, photos
.get(DatabaseHandler.KEY_THUMBNAILPATH).get(1), false);
}
cacheView.image = (ImageView)convertView.findViewById(R.id.list_image);//iv;
cacheView.tags = flow;
convertView.setTag(cacheView);
}
cacheView = (ViewHolder) convertView.getTag();
cacheView.image.setImageBitmap(null);
DecodeTask task = new DecodeTask(cacheView.image);
task.execute(photos.get(DatabaseHandler.KEY_THUMBNAILPATH).get(1));
cacheView.image.setTag(R.id.list_image, task);
return convertView;
}
static class ViewHolder {
static FlowLayout tags;
static ImageView image;
public static FlowLayout getFlowLayout() {
return tags;
}
}
}
流程布局来自这里 - http://nishantvnair.wordpress.com/2010/09/28/flowlayout-in-android/ 气泡布局来自这里 - http://nishantvnair.wordpress.com/2010/09/ 28/android-create-bubble-like-facebook/ 我使用这个 SO 线程在后台加载图像 - 包含 Android 中图像的大型 ListView 有 什么帮助吗?=\ ps 我知道已经有这样的应用程序[实际上很多,但是最好的学习来自于编写代码,所以这就是我所做的 =)]