有没有办法将List <spanned>放在SaveInstanceState包中?</spanned>

时间:2013-12-31 14:56:56

标签: java android spanned

我正在尝试在我的Android应用程序中的SaveInstanceState中存储2个String ArrayLists和1个Spanned ArrayList。这可能吗?如果是这样,你能提供一个例子吗?

ArrayListList<String> businessNames = new ArrayList<String>();
List<Spanned> businessInfo = new ArrayList<Spanned>();
ArrayList<String> businessCategories = new ArrayList<String>();


protected void onSaveInstanceState(Bundle bundle) {
    super.onSaveInstanceState(bundle);
    bundle.putStringArrayList("businessNames", businessNames);
    bundle.putStringArrayList("businessCategories", businessCategories);
    // ??????
    bundle.putParcelableArrayList("businessInfo", businessInfo); 
}

1 个答案:

答案 0 :(得分:-1)

我自己解决了这个问题。这是下面的代码......

ArrayList<String> businessNames = new ArrayList<String>();
List<Spanned> businessInfo = new ArrayList<Spanned>();
ArrayList<String> businessCategories = new ArrayList<String>();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    expListView = (ExpandableListView) findViewById(R.id.lvExp);
    String userChoice = (String) getIntent().getExtras().get("userChoice");

        if (savedInstanceState != null){
            businessInfo = (List<Spanned>) savedInstanceState.getSerializable("businessInfo");
            businessNames = savedInstanceState.getStringArrayList("businessNames");
            businessCategories = savedInstanceState.getStringArrayList("businessCategories");

            new DisplaySavedResults().execute();

        } else {
            new RetreiveSearchResults().execute(userChoice);
        }
}


protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putStringArrayList("businessNames", businessNames);
    savedInstanceState.putStringArrayList("businessCategories", businessCategories);
    savedInstanceState.putSerializable("businessInfo", (Serializable) businessInfo);
}

新的asynctask DisplaySavedResults只是在onPostExecute中改变了UI。 doInBackground留空。