小编ViT*_*al-的帖子

麻烦与活动标题语言

我的应用程序中有两种语言.values/strings.xmlvalues-ru/strings.xml当我以编程方式更改语言时,所有字符串都会进行转换,但活动标题不会更改.我在所有活动中使用

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String languageToLoad  = prefs.getString("prefLanguage","en");
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
        getBaseContext().getResources().getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)

当我选择语言时,重新加载活动或应用程序.

android

20
推荐指数
3
解决办法
4568
查看次数

GCM java服务器示例

有没有人有GCM java第三方服务器示例的链接?我无法理解如何实现它.在http://developer.android.com/google/gcm/server.html中,我找不到完整的示例.

android google-cloud-messaging

13
推荐指数
1
解决办法
2万
查看次数

适用于Google健身的HealthDataTypes的范围

我想读HealthDataTypes.Scope我必须在创建时设置哪个GoogleApiClient

.addScope(new Scope(????))
Run Code Online (Sandbox Code Playgroud)

android google-fit-sdk google-fit

6
推荐指数
1
解决办法
433
查看次数

使用 Gson 反序列化 Map<String, List<?>>

我在服务器中序列化数据:

Gson gson = new Gson();
Map<String, List<?>> resultMap = BackendUpdateManager.getInstance()
    .getUpdates(timeHolder, shopIdInt, buyerIdInt);
gson.toJson(resultMap);
Run Code Online (Sandbox Code Playgroud)

并反序列化:

Gson gson = new Gson();
Map<String, List<?>> resultMap =  gson.fromJson(json,
    new TypeToken<Map<String, List<?>>>() {
    }.getType());
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用以下项目时Map

List<ProductCategory> productCategoryList = (List<ProductCategory>)updateMap.get(key);

for(ProductCategory productCategory : productCategoryList) {

}
Run Code Online (Sandbox Code Playgroud)

我得到错误:

造成的:java.lang.ClassCastException:com.google.gson.internal.LinkedTreeMap不能强制转换为com.example.model.entity.ProductCategory

如何修复此错误或以其他方式创建 Mapwith List<different classes>

我尝试使用 getter 和 setter 创建类,其中包含List不同类的 s 而不是Map<String, List<?>>并将其用于序列化和反序列化。但我正在寻找更好的方法。

java android json gson

5
推荐指数
1
解决办法
2102
查看次数

如何在模型中获取图像变体的网址(在控制器/视图外部)?活动存储

我可以使用以下代码在模型中获取url(活动存储)

Rails.application.routes.url_helpers.rails_blob_path(picture_of_car, only_path: true)

但是我需要获取调整后的瓦里安网址

picture_of_car.variant(resize: "300x300").processed

例如此代码

Rails.application.routes.url_helpers.rails_blob_path(picture_of_car.variant(resize: "300x300").processed, only_path: true)

NoMethodError (undefined method `signed_id' for #< ActiveStorage::Variant:0x0000000004ea6498 >):
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rails-activestorage

3
推荐指数
1
解决办法
1848
查看次数