Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android将Json提要中的图像馈送到列表中_Android_Json_Image - Fatal编程技术网

Android将Json提要中的图像馈送到列表中

Android将Json提要中的图像馈送到列表中,android,json,image,Android,Json,Image,嗨,我有一个列表,我让它从一个Json提要中填入一个标题,现在我想给它添加一个图像,这是我的单张列表布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:p

嗨,我有一个列表,我让它从一个Json提要中填入一个标题,现在我想给它添加一个图像,这是我的单张列表布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"

    android:padding="6dip">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true" />

<TextView 
    android:orientation="vertical"
    android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    android:background="@drawable/ic_gr_arrow"
    android:id="@+id/textView1" 
   android:textColor="@color/blue"
   android:padding="20dp"
   android:textSize="10dp" 

     />


</RelativeLayout>
这是到目前为止我的密码

String json = reader.readLine();





            // Instantiate a JSON object from the request response
            JSONObject obj = new JSONObject(json);
            List<String> items = new ArrayList<String>();


            JSONObject objData = obj.getJSONObject("data");

            JSONArray jArray = objData.getJSONArray("news");


            for (int i=0; i < jArray.length(); i++)
            {    JSONObject oneObject = jArray.getJSONObject(i);
                items.add(oneObject.getString("title"));
                 Log.i("items", "items");
            }

            setListAdapter ( new ArrayAdapter<String>(this, R.layout.single_item, items));
            ListView list = getListView();
            list.setTextFilterEnabled(true);


            list.setOnItemClickListener(new OnItemClickListener(){

                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    // TODO Auto-generated method stub
                    Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(),1000).show();
                }



            });


        } catch(Exception e){
            // In your production code handle any errors and catch the individual exceptions
            e.printStackTrace();
        }
String json=reader.readLine();
//从请求-响应实例化JSON对象
JSONObject obj=新的JSONObject(json);
列表项=新建ArrayList();
JSONObject objData=obj.getJSONObject(“数据”);
JSONArray jArray=objData.getJSONArray(“新闻”);
for(int i=0;i
我假设您希望为listview中的每个项目加载图像,如果是这种情况,那么您可以从下面实现任何解决方案:

  • String json = reader.readLine();
    
    
    
    
    
                // Instantiate a JSON object from the request response
                JSONObject obj = new JSONObject(json);
                List<String> items = new ArrayList<String>();
    
    
                JSONObject objData = obj.getJSONObject("data");
    
                JSONArray jArray = objData.getJSONArray("news");
    
    
                for (int i=0; i < jArray.length(); i++)
                {    JSONObject oneObject = jArray.getJSONObject(i);
                    items.add(oneObject.getString("title"));
                     Log.i("items", "items");
                }
    
                setListAdapter ( new ArrayAdapter<String>(this, R.layout.single_item, items));
                ListView list = getListView();
                list.setTextFilterEnabled(true);
    
    
                list.setOnItemClickListener(new OnItemClickListener(){
    
                    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                            long arg3) {
                        // TODO Auto-generated method stub
                        Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(),1000).show();
                    }
    
    
    
                });
    
    
            } catch(Exception e){
                // In your production code handle any errors and catch the individual exceptions
                e.printStackTrace();
            }