【问题标题】:getString from strings.xml in AppWidgetProvider从 AppWidgetProvider 中的 strings.xml 获取字符串
【发布时间】:2011-11-14 13:03:31
【问题描述】:

我在正常活动中有这个:

tv.setText(this.getString(R.string.week1));

我觉得

remoteViews.setTextViewText(R.id.widget_textview,"something");

等价于

tv.setText("something");

如何从 AppWidgetProvider 中的 strings.xml 中获取字符串?

可能有一个非常简单的解决方案,但我尝试使用 google 并且我是 android 新手...

【问题讨论】:

  • 我不知道如何“如何从 AppWidgetProvider 中的 strings.xml 获取字符串?”但我认为您尝试从 strings.xml 获取字符串

标签: android android-widget widget


【解决方案1】:

因此,当您获得 Context 时,您只需调用

context.getString(resIdHere);

onEnable()、onDisable()、onReceive() 和 onUpdate() 方法都默认将上下文引用传递给它们的定义。

希望对你有帮助,

-serkan

【讨论】:

  • 非常感谢!!我知道上下文与此有关,哈哈! remoteViews.setTextViewText(R.id.widget_textview,context.getString(R.string.week1));工作
【解决方案2】:

我不知道如何“如何从 AppWidgetProvider 中的 strings.xml 获取字符串?”但我认为您尝试从 strings.xml 获取字符串

可以这样完成。

String s = getResources().getString(R.string.-yourString);

【讨论】:

    猜你喜欢
    • 2012-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多