gpt4 book ai didi

php - 将图像字符串 URL 显示到 ListView Android PHP 到 JSON 数组

转载 作者:行者123 更新时间:2023-11-29 01:51:48 25 4
gpt4 key购买 nike

所以我一直致力于网络服务。但是我遇到了这个问题,我不知道如何在我的 ListView 中显示图像。我从 JSON 数组中获取数据。下面是我的代码:

  // url to make request
private static String url = "http://alyssayango.x10.mx/";

private static final String TAG_TYPE = "movie_type";
private static final String TAG_NAME = "movie_name";
private static final String TAG_LENGTH = "movie_length";
private static final String TAG_SCHEDULES = "movie_schedules";
private static final String TAG_CINEMA = "movie_cinema_number";
private static final String TAG_URL = "movie_image_url";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String readMovieSchedules = readMovieSchedules();

// Hashmap for ListView
ArrayList<HashMap<String, String>> movieList = new ArrayList<HashMap<String, String>>();

try {
JSONArray jsonArray = new JSONArray(readMovieSchedules);
Log.i(MainActivity.class.getName(),
"Number of entries " + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.i(MainActivity.class.getName(), jsonObject.getString("movie_name"));

// Storing each json item in variable
String name = jsonObject.getString(TAG_NAME);
String type = jsonObject.getString(TAG_TYPE);
String length = jsonObject.getString(TAG_LENGTH);
String cinema = jsonObject.getString(TAG_CINEMA);
String schedules = jsonObject.getString(TAG_SCHEDULES);
String url = jsonObject.getString(TAG_URL);

// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();

// adding each child node to HashMap key => value
map.put(TAG_NAME, name);
map.put(TAG_TYPE, type);
map.put(TAG_LENGTH, length);
map.put(TAG_CINEMA, cinema);
map.put(TAG_SCHEDULES, schedules);
map.put(TAG_URL, url);

// adding HashList to ArrayList
movieList.add(map);

String strURL = TAG_URL.replaceAll(" ", "%20");

/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, movieList,
R.layout.list_item,
new String[] { strURL, TAG_NAME, TAG_CINEMA, TAG_SCHEDULES },
new int[] { R.id.image, R.id.name, R.id.cinema, R.id.schedules });

setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();

结果只显示文本而不显示图像,我的 logcat 抛出:resolveURi failed on bad bitmap uri: http://www.sample.com/file.jpg

非常感谢您的帮助。我是 Android 新手。

最佳答案

使用 ImageLoader、Utils、FileCache 和 MemoryCache.java 文件并在您的适配器中编写此代码

ImageLoader iv_loader = new ImageLoader(main_activity.context);
iv_loader.DisplayImage(msgs.Image,image);
返回 v;
msgs 是获取点击项位置的类名变量。图像是 ImageView 名称。

我希望并确定这段代码可以正常工作

关于php - 将图像字符串 URL 显示到 ListView Android PHP 到 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17533593/

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