我想學習android sqlite,所以我創建了一個即時標記應用程序,用戶可以在其中標記他的照片並將其上傳到他的網絡(google +,fb,twitter)問題是我有一個ListFragment
其中用戶可以看到他所做的所有標記,列表中的圖像元素存儲在一個隱藏的文件夾和單詞存儲在一個sqlite數據庫..問題是滾動向上或向下一些項目只是隨機切換,即使我有更多比8個項目多8個第一項顯示重複(即1-8而不是9-12我再次看到1-4) 唯一的問題可能是在適配器,但在調試會話的會話後,我無法找到問題我的適配器代碼是 -listfragment中的奇怪錯誤
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線程至後臺加載圖像 - Large ListView containing images in Android 任何幫助嗎? = \ p.s 我知道已經有這樣的應用程序[但實際上,但最好的學習來編寫代碼,因此我做了=]]
如何放置此行** cacheView =(ViewHolder)convertView.getTag(); **在else條件內?不知道它是否會有幫助,但你可以試試看? –
仍然沒有效果...我懷疑它有某種方式連接到flowlayout或bubbleview,因爲它們是動態的(換句話說,沒有id附加到泡泡佈局我只是將它們添加到運行時的flowlayout看看他們在我添加的鏈接上的實施) – crazyPixel