我想将Drawable转换为int,然后再进行反向转换。基本上,我想将ArrayList对象保存到sharedPrefrence中。为此,我已经实现了一个Gson转换方法来将其转换为字符串。如果我在这里使用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转换为字符串的源代码,以便我可以将其保存到SharedPreference中。
Gson gson = new Gson();
apps.get(number).setColor(picker.getColor());
String JsonAppsdata = gson.toJson(apps);
System.out.println("Storing="+JsonAppsdata);
utility.StoreData(getApplicationContext(), JsonAppsdata);