Android setlistAdapter错误

时间:2012-03-07 22:23:49

标签: android

嗨,只是出错,我不确定为什么有人可以帮忙?

这就是我的json feed的结构,我想要新闻数组

{ “代码”:200, “错误”:NULL, “数据”:{ “新闻”:[{ “news_id”: “8086” 我在这里得到一个错误:在oneOjectsItem

setListAdapter(new ArrayAdapter(this,R.layout.single_item,oneObjectsItem));

这里是我的代码

        // Instantiate a JSON object from the request response
        JSONObject jsonObject = new JSONObject(json);



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


        for (int i=0; i < jArray.length(); i++)
        {
            JSONObject oneObject = jArray.getJSONObject(i);
            // Pulling items from the array
            String oneObjectsItem = oneObject.getString("title");



        }


    } catch(Exception e){
        // In your production code handle any errors and catch the individual exceptions
        e.printStackTrace();
    }




    setListAdapter ( new ArrayAdapter<String>(this, R.layout.single_item, oneObjectsItem)); 



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();
    }



});

}

1 个答案:

答案 0 :(得分:0)

初始化list元素后使用setListAdapter。您可以找到详细的示例here.