我想将Drawable转换为int,然后反之亦然。基本上我想将Arraylist对象保存到sharedPrefrence。为此,我实施了Gson到 Srtring 的转换方法。如果我在这里使用Drawable而不是int那么 Gson 字符串转换需要很多时间。所以我想使用 int 而不是 Drawable。
private List<AppInfo> apps = null;
public void setIcon(int icon) {
this.icon = icon;
}
apps.get(position).setIcon(mContext.getResources().getDrawable(apps.get(position).getIcon()));
这里的 AppInfo 在哪里
public AppInfo(String appname, String pname, String versionName, int versionCode, int icon, int color) {
this.appname = appname;
this.pname = pname;
this.versionName = versionName;
this.versionCode = versionCode;
this.icon = icon;
this.color = color;
}
这是将自定义对象的 ArrayList 转换为字符串的来源,以便我可以将其保存到 SharedPrefrence。
Gson gson = new Gson();
apps.get(number).setColor(picker.getColor());
String JsonAppsdata = gson.toJson(apps);
System.out.println("Storing="+JsonAppsdata);
utility.StoreData(getApplicationContext(), JsonAppsdata);