【问题标题】:From JSON database use string for dimens [duplicate]从 JSON 数据库使用字符串作为尺寸 [重复]
【发布时间】:2017-12-21 09:13:41
【问题描述】:

我正在使用 JSON 数据库。
在里面我更喜欢有字符串。

如果我将“singleImage_marginTop”之类的内容作为字符串存储在 JSON 文件中,我可以获得该字符串,但如何将其转换为可以在此处使用的内容?

image.setPadding(R.dimen.(the_string_to_be_used_here));

【问题讨论】:

标签: android json string


【解决方案1】:
Context context = image.getContext();
int padding = context.getResources().getIdentifier("the_string_to_be_used_here", "dimen", context.getPackageName());
image.setImageResource(padding);

试试这个。

【讨论】:

    【解决方案2】:

    我尝试将它用于列表视图,但对我而言,上述解决方案均无效。

    我改为使用字符串来识别给定视图的预期属性,并基于该字符串在 listadapter 中为不同类型的视图设置属性。

    这样更容易也更安全。

    【讨论】:

      猜你喜欢
      • 2013-11-25
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 1970-01-01
      • 2018-10-28
      • 2012-04-22
      • 2012-09-22
      相关资源
      最近更新 更多