在Android中加载json数据-uitableview
问题描述:
请帮助!在Android中加载json数据-uitableview
在我的应用程序使用Android-UiTableView
( thiagolocatelli/android-uitableview)和AQuery
( androidquery/androidquery)
我的任务就是让来自URL JSON数组和负载图像数据的加载。 负载没有图片列表我能:
jgall = json.getJSONArray("gall");
int z = 0;
for(int i = 0; i < jgall.length(); i++){
JSONObject c = jgall.getJSONObject(i);
tableView.addBasicItem(c.getString("name"), c.getString("place"));
}
我试图表明一个自定义视图,并没有任何反应
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout view = (RelativeLayout) mInflater.inflate(R.layout.custom_view,null);
String iurl = c.getString("img");
aq.id(R.id.img).image(iurl, false, true);
ViewItem viewItem = new ViewItem(view);
tableView.addViewItem(viewItem);
告诉我,这是真正使用Android-UiTableView
做什么呢?如果是这样!怎么样?
答
我已经通过自己修改库代码来完成此操作。
我已经添加下面的构造在UITableView.java:
public void addBasicItem(Drawable drawable, String title, String summary) {
mItemList.add(new BasicItem(drawable, title, summary));
}
而在BasicItem.java如下:
public Drawable getDDrawable() {
return dDrawable;
}
public BasicItem(Drawable ddrawable, String _title, String _subtitle) {
this.dDrawable = ddrawable;
this.mTitle = _title;
this.mSubtitle = _subtitle;
}
并再次修改setupBasicItem方法在UITableView.java file:
((ImageView) view.findViewById(R.id.image)).setBackgroundDrawable(item.getDDrawable());
最后,在你的代码添加以下内容:
URL newurl = new URL("http://www.example.com/example.png");
Bitmap bmp = BitmapFactory.decodeStream(newurl.openConnection() .getInputStream());
Drawable drawable = new android.graphics.drawable.BitmapDrawable(getResources(),bmp);
tableView.addBasicItem(drawable, "Title", "SubTitle");
希望它能帮助,因为它为我工作。
+0
完美工作!当然,这应该是显而易见的,但是你也必须添加一个私人的Drawable dDrawable到BasicItem.java。 – MacD
我认为你正在寻找这个:[Android - 异步图像加载ListView](http://www.technotalkative.com/android-asynchronous-image-loading-in-listview/) –