我有一个扩展列表,它是由 组成的HashMap<String, List<String>>
,我想知道是否有可能将该值存储到首选项或其他东西中,以便用户可以编辑扩展列表条目。任何信息,建议将不胜感激。
目前我正在程序中创建列表,它没有保存到任何首选项:
public class MainActivity extends Activity{
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding header data
listDataHeader.add("Vegetables");
listDataHeader.add("Fruits");
listDataHeader.add("Drinks");
// Adding child data
List<String> vegetables = new ArrayList<String>();
vegetables.add("Tomatoes");
vegetables.add("Potatoes");
vegetables.add("Cucumbers");
vegetables.add("Pumpkins");
vegetables.add("Peppers");
vegetables.add("Onions");
vegetables.add("Garlic");
List<String> fruits = new ArrayList<String>();
fruits.add("Strawberries");
fruits.add("Blackcurrants");
fruits.add("Redcurrant");
fruits.add("Gooseberry");
fruits.add("Kiwifruit");
fruits.add("Grape");
List<String> drinks = new ArrayList<String>();
drinks.add("Vodka");
drinks.add("Milk");
drinks.add("Water");
drinks.add("CocaCola");
drinks.add("Sprite");
listDataChild.put(listDataHeader.get(0), vegetables); // Header, Child data
listDataChild.put(listDataHeader.get(1), fruits);
listDataChild.put(listDataHeader.get(2), drinks);
}
private String does(String child) {
Intent intent = new Intent(this, Confirmation.class);
intent.putExtra("key", child);
startActivity(intent);
return null;
}
}
日志
09-29 17:21:42.039: E/dalvikvm(25076): Could not find class 'com.google.gson.Gson', referenced from method lt.whiteGroup.ultimateshoppinglist.MainActivity.prepareListData
09-29 17:21:42.125: E/AndroidRuntime(25076): FATAL EXCEPTION: main
09-29 17:21:42.125: E/AndroidRuntime(25076): java.lang.NoClassDefFoundError: com.google.gson.Gson
09-29 17:21:42.125: E/AndroidRuntime(25076): at lt.whiteGroup.ultimateshoppinglist.MainActivity.prepareListData(MainActivity.java:117)
09-29 17:21:42.125: E/AndroidRuntime(25076): at lt.whiteGroup.ultimateshoppinglist.MainActivity.onCreate(MainActivity.java:45)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.os.Looper.loop(Looper.java:130)
09-29 17:21:42.125: E/AndroidRuntime(25076): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-29 17:21:42.125: E/AndroidRuntime(25076): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 17:21:42.125: E/AndroidRuntime(25076): at java.lang.reflect.Method.invoke(Method.java:507)
09-29 17:21:42.125: E/AndroidRuntime(25076): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-29 17:21:42.125: E/AndroidRuntime(25076): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-29 17:21:42.125: E/AndroidRuntime(25076): at dalvik.system.NativeStart.main(Native Method)