0

在这里我发布了myservice.java的一部分,我想在android中的其他类中传递“服务”类的arraylist;所以怎么做,我对android非常天真。我想设置guestorderlist arraylist的值在列表视图中。

public void onStart(Intent intent, int startId) {
     // TODO Auto-generated method stub
    super.onStart(intent, startId);
    Toast.makeText(this, "service got started", Toast.LENGTH_LONG).show();
    Log.d("Testing", "Service got started");
    {
        {


            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_all_guests, "GET", params);

            // Check your log cat for JSON reponse
            Log.d("All custinfo: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // custinfo found
                    // Getting Array of custinfo
                    custinfo = json.getJSONArray(TAG_CUSTINFO);

                    // looping through All custinfo
                    for (int i = 0; i < custinfo.length(); i++) {
                        JSONObject c = custinfo.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_PID);
                        String gname =  c.get(TAG_GNAME).toString();

                        // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();  

                        // adding each child node to HashMap key => value
                        map.put(TAG_PID, id);
                        map.put(TAG_GNAME, gname);

                        // adding HashList to ArrayList
                        guestsorderList.add(map);

                    }
                } 
            } catch (JSONException e) {
                e.printStackTrace();
            }


        }
    }

      }
4

1 回答 1

0

我可以从您的问题中得到的是,您希望将 ArrayList 从一项活动传递到另一项活动。如果这就是问题所在,您可以将 ArrayList 从一个父活动传递给被调用的活动。这是一个示例:

ArrayList<TYPE> value = new ArrayList<TYPE>();
// populate the list
value.add(1.0);
Intent intent = new Intent(CurrentActivity.this,TargetActivity.class);
intent.putExtra("arraylist", value);
startActivity(intent);

在目标类中,您可以按如下方式检索列表:

// Call in in OnCreate()
// TYPE can be String, Double etc.
ArrayList<TYPE> list=(ArrayList<TYPE>)getIntent().getSerializableExtra("arraylist");
于 2013-03-17T12:05:44.227 回答