这里我发布了myservice.java的一部分,我想在android中的其他类中传递“service”类的arraylist;所以如何做到这一点,我对于android.i非常天真想要设置值列表视图中的 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();
}
}
}
}
答案 0 :(得分: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");