GridView アダプターに問題があります。最初の読み込みは正常に機能しますが、結果に写真が 1 つしかないことを知っていても、スワイプして再読み込みするたびに最初の画像が空のグリッド ビュー スポットに追加されます。
写真は説明に役立ちます。
したがって、GridAdapter がデータを正しく処理していないと思われますが、何が欠けているのかわかりません。
これは、AsyncHttpClient が API からデータを取得した後にアダプターを呼び出す onSuccess です。
@Override
public void onSuccess(JSONObject jsonObject) {
swipeLayout.setRefreshing(false);
Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();
JSONArray list = jsonObject.optJSONArray("photos");
for (int i = 0; i < list.length(); i++){
try {
photoUrlList.add(list.getJSONObject(i).getString("thumb_url"));
} catch (JSONException e) {
e.printStackTrace();
}
}
mFourGridAdapter.updateData(photoUrlList);
}
私の MyFourGridAdapter:
private class MyFourGridAdapter extends BaseAdapter
{
private LayoutInflater inflater;
private List<String> photoUrlList;
public MyFourGridAdapter(Context context, List<String> photoUrlList ) {
inflater = LayoutInflater.from(context);
this.photoUrlList = photoUrlList;
}
public void updateData(List<String> values) {
// update the adapter's dataset
photoUrlList = values;
notifyDataSetChanged();
}
@Override
public int getCount() {
return photoUrlList.size();
}
@Override
public Object getItem(int i)
{
return photoUrlList.get(i);
}
@Override
public long getItemId(int i)
{
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View v = view;
ImageView picture;
if(v == null) {
v = inflater.inflate(R.layout.gridview_item, viewGroup, false);
v.setTag(R.id.frame_square_image_view, v.findViewById(R.id.frame_square_image_view));
}
picture = (ImageView)v.getTag(R.id.frame_square_image_view);
String photoUrl = photoUrlList.get(i);
Picasso.with(picture.getContext()).load(photoUrl).into(picture);
return v;
}
}
不明な点があればコメントしてください - 説明が少し難しいです。どんな助けでも大歓迎です、ありがとう。