Pass a TreeMap from one activity to other
I have a
TreeMap<String, ArrayList<Video>> mShows = new TreeMap<String, ArrayList<Video>>();
and I'm trying to pass from one activity to another. I have tried
"putExtra treeMap returns HashMap cannot be cast to 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"));
}
but it says that Map, String and the ArrayList cannot be resolved to a variable where I have (Map>)
This is how I add it
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>>();
There's one closing bracket missing, just before getIntent(). Correct form:
mShows = new TreeMap<String, ArrayList<Video>>((TreeMap<String, ArrayList<Video>>) getIntent().getExtras().get("map"));
链接地址: http://www.djcxy.com/p/67902.html
上一篇: Android广播意图