【发布时间】:2015-07-25 19:53:13
【问题描述】:
我是 android 的初学者,我想编写一个简单的应用程序来从服务器读取图像和数据并显示到列表视图中,我的列表视图 xml 文件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_gravity="center"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/abc_btn_check_material" />
<TextView
android:id="@+id/textView1"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="TextView" />
</LinearLayout>
并使用此方法从服务器读取 json 数据:
....READ WITH ASYNCTASK
try {
JSONArray jsonArray=new JSONArray(result);
prgmNameList=new String[jsonArray.length()];
prgmImages=new int[jsonArray.length()];
for(int i=0;i<jsonArray.length();i++)
{
JSONObject JsonObj=jsonArray.getJSONObject(i);
String TITLES=JsonObj.getString("title");
String imgURL=JsonObj.getString("img");
Log.d("BEHZAD TITLES=",TITLES);
.....I want read the image and show into the listview with title
}
我该如何解决这个计划?谢谢。
【问题讨论】:
-
URL newurl = new URL(photo_url_str); mIcon_val = BitmapFactory.decodeStream(newurl.openConnection() .getInputStream()); profile_photo.setImageBitmap(mIcon_val);在这里回答stackoverflow.com/questions/2471935/…