[英]Display these json images as listview
I have successfully parsed my json images and displayed the response as image ,however I can only display one image at a time. 我已经成功解析了json图像并将响应显示为image,但是一次只能显示一个图像。
How can I display these images as listview using this code. 如何使用此代码将这些图像显示为列表视图。
Before posting this question I have also looking to this solution. 在发布此问题之前,我还期待着这种解决方案。 I want to display these images as listview along with my other json values using using the below code. 我想使用以下代码将这些图像与其他json值一起显示为listview。
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
JSONParser prop = new JSONParser();
JSONObject json = prop.getJSONFromUrl(url);
try{
properties = json.getJSONArray(TAG_PROPERTY);
for (int i = 0; i < properties.length(); i++) {
JSONObject c = properties.getJSONObject(i);
String photoThumbnailUrl = c.getString(TAG_PHOTOS);
// load image view control
imgView = (ImageView) findViewById(R.id.imgView);
// grab image to display
try {
imgView.setImageDrawable(grabImageFromUrl(photoThumbnailUrl));
} catch (Exception e) {
txtUrl.setText("Error: image not grabed");
}
}
}catch (Exception ex) {
txtUrl.setText("Error: Properties not recieved");
}
}
private Drawable grabImageFromUrl(String photoThumbnailUrl) {
System.out.println(photoThumbnailUrl);
// TODO Auto-generated method stub
return null;
}
//from here only one image is displayed....
//start the listview here
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("ok");
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
//convertView = inflater.inflate(R.layout.list_items, null);
holder = new ViewHolder();
holder.identifier= (TextView) convertView
.findViewById(R.id.identifier);
holder.price = (TextView) convertView.findViewById(R.id.price);
holder.address = (TextView) convertView.findViewById(R.id.address);
holder.photoThumbnailUrl = (ImageView) convertView
.findViewById(R.id.imgView);
convertView.setTag(holder);
System.out.println("identifier");
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
class ViewHolder{
public TextView identifier;
public TextView price;
public TextView address;
public ImageView photoThumbnailUrl;
}
}
Many thanks 非常感谢
For list views you need to download the new content for each row. 对于列表视图,您需要为每一行下载新内容。
This can be tricky to be done correctly. 要正确完成此操作可能很棘手。 I have created a helper here: https://github.com/mufumbo/android-helper/blob/master/src/com/mufumbo/android/helper/ThumbLoader.java 我在这里创建了一个帮助器: https : //github.com/mufumbo/android-helper/blob/master/src/com/mufumbo/android/helper/ThumbLoader.java
Example of usage: 用法示例:
Make your ViewHolder to implement the {@link ThumbLoader.ThumbEvent} and then when populating the ViewHolder: 使您的ViewHolder实现{@link ThumbLoader.ThumbEvent},然后在填充ViewHolder时:
ThumbLoader thumbLoaderInstance; ThumbLoader thumbLoaderInstance;
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position,View convertView,ViewGroup parent){
.... ....
thumbLoaderInstance.pushEvent(holder, true); thumbLoaderInstance.pushEvent(holder,true);
.... ....
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.