1

我正在尝试从 a 中检索值,json api然后在 listView 中显示。包含 3 个元素,listView我也在实现onItemClickListner(),当单击一个项目时,它将显示与该项目相关的详细视图。我正在使用 anArrayList来存储所有json值。现在我想从中检索一个值,ArrayList以便OnClickListner()获取该值,并从该值显示详细视图。

我正在使用 AsyncTask 检索所有 json 值

@Override
protected String doInBackground(String... DATA) {
if(rqst_type.equals("top5"))
    {
        String url = DATA[1];
        JsonParser jParser = new JsonParser();
        JSONObject json = jParser.getJSONfromUrl(url);
        try
        {
            JSONArray top5 = json.getJSONArray(TAG_TOP5);
            public static ArrayList<HashMap<String, String>> top5List = new ArrayList<HashMap<String, String>>();
            top5List.clear();
            for(int i=0; i<top5.length(); i++)
            {
                Log.v(TAG_LOG, "Value of i: "+String.valueOf(i));
                JSONObject t = top5.getJSONObject(i);
                course_id = t.getString(TAG_CRSID);
                created_date = t.getString(TAG_CRTDATE);
                golfcourse_name = t.getString(TAG_GLFCRSNAME);
                facilities = t.getString(TAG_FCLTY);
                holes = t.getString(TAG_HOLES);

                HashMap<String, String> map = new HashMap<String, String>();
                map.put(TAG_CRSID, course_id);
                map.put(TAG_CRTDATE, created_date);
                map.put(TAG_GLFCRSNAME, golfcourse_name);
                map.put(TAG_FCLTY, facilities);
                map.put(TAG_HOLES, holes);

                top5List.add(map);
                Log.v(LoadingScreen.TAG_LOG, "top5List: "+String.valueOf(top5List));
            }
        }
        catch(JSONException e)
        {
            Log.v(TAG_LOG, String.valueOf(e));
        }
}

protected void onPostExecute(String result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);
    if(rqst_type.equals("top5"))
    {
        Intent in = new Intent(context, MyTop5.class);
        in.putExtra(TAG_CRSID, course_id);
        in.putExtra(TAG_CRTDATE, created_date);
        in.putExtra(TAG_GLFCRSNAME, golfcourse_name);
        in.putExtra(TAG_FCLTY, facilities);
        in.putExtra(TAG_HOLES, holes);
        Log.v(TAG_LOG, "Valuse to MyTop5: "+course_id+" "+created_date+" "+golfcourse_name+" "+
                facilities+" "+holes);
        context.startActivity(in);
    }

这是我要显示列表的文件和onItenClickListner()..

 @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_top5);

    Intent in = getIntent();
    golfcourse_name = in.getStringExtra(TAG_GLFCRSNAME);
    course_id = in.getStringExtra(TAG_CRSID);
    created_date = in.getStringExtra(TAG_CRTDATE);
    facilities = in.getStringExtra(TAG_FCLTY);
    holes = in.getStringExtra(TAG_HOLES);
    Log.v(LoadingScreen.TAG_LOG, "course id: "+String.valueOf(course_id));
    ListAdapter adapter = new SimpleAdapter(this, LoadingScreen.top5List, R.layout.top5_list,
            new String[] { TAG_GLFCRSNAME, TAG_CRSID, TAG_CRTDATE, TAG_FCLTY, TAG_HOLES },
            new int[] { R.id.top_golfname, R.id.top_courseid, R.id.top_createdate, R.id.top_fclty, R.id.top_holes });

    setListAdapter(adapter);
    Log.v(LoadingScreen.TAG_LOG, "course id: "+String.valueOf(course_id));
    ListView lv = getListView();

    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            String url = "http://mygogolfteetime.com/iphone/viewdeal/127";
            new LoadingScreen(MyTop5.this).execute("view_detail", url);
        }
    });
}

在给定的 URL 中,我想将 127 更改为存储在top5List.

String url = "http://mygogolfteetime.com/iphone/viewdeal/127";

我试图在 中找到top5List的值是“ course_id”的值

提前致谢..

4

1 回答 1

3
top5List.get(your position).get(your Key);

使用此代码,您可以找到要更改的值。

于 2012-08-20T08:25:49.050 回答