gpt4 book ai didi

java - 当更改 GridView 的行时,它会显示第一张图像

转载 作者:行者123 更新时间:2023-11-30 05:06:16 25 4
gpt4 key购买 nike

在我的应用程序中,我只能上传五张图片,当我上传 3 或 5 张时,它工作正常,但当我只上传四张图片(然后换行)时,它在位置 3 和位置 0 上显示相同的图片。

 public void showList(final JSONArray responsearray) {
try {
for (int i = 0; i < responsearray.length(); i++) {
JSONObject responseObject = responsearray.getJSONObject(i);
Log.e("COUNT" + i, String.valueOf(responseObject));
imageOne = responseObject.getString(TAG_PHOTO_ONE);
get = new HashMap<>();
get.put(TAG_PHOTO_ONE, imageOne);
myList.add(get);
}
adapter = new SimpleAdapter(getActivity(), myList, R.layout.row_more_images,
new String[]{TAG_PHOTO_ONE},
new int[]{R.id.photo1}) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View v = super.getView(position, convertView, parent);
if (convertView == null) {
TextView photo1 = v.findViewById(R.id.photo1);
photoOne = v.findViewById(R.id.photo_one);
String imgPath = getString(R.string.moreimgpath);
if (!photo1.getText().toString().equalsIgnoreCase("null")) {
final_image_url = imgPath + photo1.getText().toString();
Log.e("FINALPATH", final_image_url);
ImageLoader.getInstance().displayImage(final_image_url, photoOne, options, animateFirstListener);
}
}
return v;
}
};
if (gridview.getAdapter() == null) {
gridview.setAdapter(adapter);
}
gridview.setOnItemClickListener(this);
} catch (JSONException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}

最佳答案

Change Code to

 public void showList(final JSONArray responsearray) {
try {
for (int i = 0; i < responsearray.length(); i++) {
JSONObject responseObject = responsearray.getJSONObject(i);
Log.e("COUNT" + i, String.valueOf(responseObject));
String imageOne = responseObject.getString(TAG_PHOTO_ONE);
HashMap<> get = new HashMap<>();
get.put(TAG_PHOTO_ONE, imageOne);
myList.add(get);
}
adapter = new SimpleAdapter(getActivity(), myList, R.layout.row_more_images,
new String[]{TAG_PHOTO_ONE},
new int[]{R.id.photo1}) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View v = super.getView(position, convertView, parent);
if (convertView == null) {
TextView photo1 = v.findViewById(R.id.photo1);
ImageView photoOne = v.findViewById(R.id.photo_one);
String imgPath = getString(R.string.moreimgpath);
if (!photo1.getText().toString().equalsIgnoreCase("null")) {
final_image_url = imgPath + photo1.getText().toString();
Log.e("FINALPATH", final_image_url);
ImageLoader.getInstance().displayImage(final_image_url, photoOne, options, animateFirstListener);
}
}
return v;
}
};
if (gridview.getAdapter() == null) {
gridview.setAdapter(adapter);
}
else{
notfyDataSetChanged();
}
gridview.setOnItemClickListener(this);
} catch (JSONException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}

关于java - 当更改 GridView 的行时,它会显示第一张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54530117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com