I have successfully parsed my json images and displayed the response as image ,however I can only display one image at a time.
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.
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
I think you should create a custom listview item with XML and use a SimpleAdapter to fill each row with the JSON items. A while back is used this article to help me out, I hope it helps you as well.
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
Example of usage:
Make your ViewHolder to implement the {@link ThumbLoader.ThumbEvent} and then when populating the ViewHolder:
ThumbLoader thumbLoaderInstance;
public View getView(int position, View convertView, ViewGroup parent) {
....
thumbLoaderInstance.pushEvent(holder, true);
....
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.