无法从json android填充列表

无法从json android填充列表,android,json,android-listview,custom-adapter,Android,Json,Android Listview,Custom Adapter,我正在尝试从api填充列表对象。 这是一种方法jsonresult protected void onPostExecute(String result) { JSONArray con; //String tag_name="tests"; //String tag_id="ID"; ArrayList<HashMap<String, String>> mylist = new ArrayList

我正在尝试从api填充列表对象。
这是一种方法jsonresult

protected void onPostExecute(String result)
    {

        JSONArray con;
        //String tag_name="tests";
        //String tag_id="ID";
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        try 
        {
            JSONObject jsonObject = new JSONObject(result);
            if("success".equals(jsonObject.getString("result")))
            {   Toast.makeText(getBaseContext(),jsonObject.getString("tests"),Toast.LENGTH_SHORT).show();
                //String nKey=jsonObject.getString("nKey");
            //  switchActivity(nKey);
                //Toast.makeText(getBaseContext(),nKey,Toast.LENGTH_SHORT).show();
                try{

                con = jsonObject.getJSONArray("tests");
                for(int i = 0; i < con.length(); i++){
                    HashMap<String, String> map = new HashMap<String, String>();
                    JSONObject c = con.getJSONObject(i);
                    map.put("EXAM", "" + c.getString("exam"));
                    map.put("ID", "" + c.getString("id"));
                    mylist.add(map);
                }}catch (JSONException e) {
                    e.printStackTrace();
                }
                ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.textview,new String[] { "exam", "id" },new int[] { R.id.exam, R.id.id });

        setListAdapter(adapter);

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);

            }
            else
            {
                Toast.makeText(getBaseContext(),jsonObject.getString("message"),Toast.LENGTH_LONG).show();
            }
        } 
        catch (Exception e)
        {
            Log.d("ReadWeatherJSONFeedTask", e.getLocalizedMessage());
        }          
    }
错误:

The constructor SimpleAdapter(examlist.ReadJSONResult, ArrayList<HashMap<String,String>>, int, String[], int[]) is undefined
构造函数simpledapter(examlist.ReadJSONResult、ArrayList、int、String[],int[])未定义

这是因为在您使用它时,
ListAdapter
没有这样的构造函数。作为
Context
(第一个参数),您正在传递
examlist.ReadJSONResult
,您应该传递一个
活动的
Context
,其中放置了使用该
列表适配器的
视图

如果要在其中设置
ListAdapter
的类不是
活动
,则应将
活动
上下文
传递给该类,并将其存储为成员字段以供进一步使用

例如,您的类名为
ReadJSONResult
。创建一个以
上下文
为参数的构造函数:

public ReadJSONResult(Context context) {
    m_context = context;  // There needs to be a field member in ReadJSONResult class called m_context
}
有鉴于此,在创建
ReadJSONResult
对象的
Activity
中,您将
Activity
上下文
传递给构造函数,然后您可以创建
列表适配器
,如下所示:

ListAdapter adapter = new SimpleAdapter(m_context, mylist , R.layout.textview,new String[] { "exam", "id" },new int[] { R.id.exam, R.id.id });

这是因为您使用的
ListAdapter
没有这样的构造函数。作为
Context
(第一个参数),您正在传递
examlist.ReadJSONResult
,您应该传递一个
活动的
Context
,其中放置了使用该
列表适配器的
视图

如果要在其中设置
ListAdapter
的类不是
活动
,则应将
活动
上下文
传递给该类,并将其存储为成员字段以供进一步使用

例如,您的类名为
ReadJSONResult
。创建一个以
上下文
为参数的构造函数:

public ReadJSONResult(Context context) {
    m_context = context;  // There needs to be a field member in ReadJSONResult class called m_context
}
有鉴于此,在创建
ReadJSONResult
对象的
Activity
中,您将
Activity
上下文
传递给构造函数,然后您可以创建
列表适配器
,如下所示:

ListAdapter adapter = new SimpleAdapter(m_context, mylist , R.layout.textview,new String[] { "exam", "id" },new int[] { R.id.exam, R.id.id });
创建一个自定义的adpeter,用于扩展列表视图。

创建一个自定义的adpeter,用于扩展列表视图。


什么是SimpleDapter的构造函数???和ListAdapter??什么是SimpleAdapter的构造函数???还有ListAdapter??
myList = (ListView) findViewById(R.id.listView1);   
myList.setAdapter(new MyListAdapter(this, UserAndMessage));