Android 如何将json url中的图像解析为listview列表项
} 我正在获取字符串值,但列表项中没有图像。 我可以得到图像作为列表项。Android 如何将json url中的图像解析为listview列表项,android,listview,Android,Listview,} 我正在获取字符串值,但列表项中没有图像。 我可以得到图像作为列表项。 这是我对json的全部解析代码,但列表项中没有静态图像。我不知道它在“良好编程实践”方面是否正确,但您必须从布局创建片段,使用另一个AsyncTask将其下载,然后使用您拥有的列表对其充气 请看这里: 我不知道它在“良好编程实践”方面是否正确,但您必须从布局创建片段,使用另一个异步任务下载它,然后使用您拥有的列表将其充气 请看这里: 试试看 1.将滑动依赖项添加到app/build.gradle private stati
这是我对json的全部解析代码,但列表项中没有静态图像。我不知道它在“良好编程实践”方面是否正确,但您必须从
布局创建片段,使用另一个AsyncTask
将其下载,然后使用您拥有的列表对其充气
请看这里:
我不知道它在“良好编程实践”方面是否正确,但您必须从布局创建片段
,使用另一个异步任务
下载它,然后使用您拥有的列表
将其充气
请看这里:
试试看
1.将滑动依赖项添加到app/build.gradle
private static final String TAG = HttpHandler.class.getSimpleName();
public HttpHandler() {
}
public String makeServiceCall(String reqUrl) {
String response = null;
try {
URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
// read the response
InputStream in = new BufferedInputStream(conn.getInputStream());
response = convertStreamToString(in);
} catch (MalformedURLException e) {
Log.e(TAG, "MalformedURLException: " + e.getMessage());
} catch (ProtocolException e) {
Log.e(TAG, "ProtocolException: " + e.getMessage());
} catch (IOException e) {
Log.e(TAG, "IOException: " + e.getMessage());
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
return response;
}
private String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
2.使用滑动加载图像
repositories {
mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
dependencies {
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:19.1.0'
}
或
试试看
1.将滑动依赖项添加到app/build.gradle
private static final String TAG = HttpHandler.class.getSimpleName();
public HttpHandler() {
}
public String makeServiceCall(String reqUrl) {
String response = null;
try {
URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
// read the response
InputStream in = new BufferedInputStream(conn.getInputStream());
response = convertStreamToString(in);
} catch (MalformedURLException e) {
Log.e(TAG, "MalformedURLException: " + e.getMessage());
} catch (ProtocolException e) {
Log.e(TAG, "ProtocolException: " + e.getMessage());
} catch (IOException e) {
Log.e(TAG, "IOException: " + e.getMessage());
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
return response;
}
private String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
2.使用滑动加载图像
repositories {
mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
dependencies {
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:19.1.0'
}
或
您正在获取图像URL,但希望显示放置在该URL上的实际图像,对吗?是的,我正在获取URL,但无法在图像位置设置它。您正在获取图像URL,但希望显示放置在该URL上的实际图像,对吗?是的,我正在获取URL,但无法在图像位置设置它。
Glide.with (context).load (url).asBitmap().into(imageView);