将TreeMap从一个活动传递给另一个活动
我有一个
TreeMap<String, ArrayList<Video>> mShows = new TreeMap<String, ArrayList<Video>>();
我试图从一个活动传递给另一个活动。 我努力了
“putExtra treeMap返回HashMap不能转换为TreeMap android”
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = getIntent();
Bundle bun = i.getBundleExtra("lascategorias");
mCategories = bun.getStringArray("categories");
mShows = new TreeMap<String, ArrayList<Video>>(Map<String,ArrayList<Video>> getIntent().getExtras().get("map"));
}
但它表示Map,String和ArrayList无法解析为我所拥有的变量(Map>)
这是我如何添加它
protected void onPostExecute(final String json) {
Log.i(LOG_TAG, "decoding...");
if (json == null)
return;
try {
final URI base = new URI(mUrl);
final JSONObject jso = new JSONObject(json);
final JSONArray ja = jso.getJSONArray("categories");
for (int i = 0; i < ja.length(); i++) {
final JSONObject list = ja.getJSONObject(i);
final ArrayList<Video> vidList = new ArrayList<Video>(10);
mShows.put(list.getString("name"), vidList);
final JSONArray videos = list.getJSONArray("videos");
for (int j = 0; j < videos.length(); j++) {
final JSONObject vids = videos.getJSONObject(j);
final JSONArray sources = vids.getJSONArray("sources");
try {
final Video v = new Video(base.resolve(vids.getString("thumb")),
base.resolve(sources.getString(0)), vids.getString("title"),
vids.getString("subtitle"), vids.getString("description"));
vidList.add(v);
// The rare case that I've got more than one
for (int k = 1; k < sources.length(); k++) {
v.mSource.add(base.resolve(sources.getString(k)));
}
} catch (IllegalArgumentException expected) {
Log.e(LOG_TAG, "Bad Json.");
}
}
}
} catch (final JSONException je) {
Log.e(LOG_TAG, "An error in the JSON." + je.getMessage());
} catch (final URISyntaxException se) {
Log.e(LOG_TAG, "URI syntax error" + se.getMessage());
}
//onDataComplete();
mCategories = getCategories();
Bundle b = new Bundle();
b.putStringArray("categories", mCategories);
//b.p
Intent i = new Intent("com.video.tv.MainActivity" );
i.putExtra("las Categorias", b);
i.putExtra("map", mShows);
startActivity(i);
finish();
}
}
I declared mShows earlier
public TreeMap<String, ArrayList<Video>> mShows = new TreeMap<String, ArrayList<Video>>();
在getIntent()之前缺少一个右括号。 正确形式:
mShows = new TreeMap<String, ArrayList<Video>>((TreeMap<String, ArrayList<Video>>) getIntent().getExtras().get("map"));
链接地址: http://www.djcxy.com/p/67901.html