• <bdo id='AA2sK'></bdo><ul id='AA2sK'></ul>

    <i id='AA2sK'><tr id='AA2sK'><dt id='AA2sK'><q id='AA2sK'><span id='AA2sK'><b id='AA2sK'><form id='AA2sK'><ins id='AA2sK'></ins><ul id='AA2sK'></ul><sub id='AA2sK'></sub></form><legend id='AA2sK'></legend><bdo id='AA2sK'><pre id='AA2sK'><center id='AA2sK'></center></pre></bdo></b><th id='AA2sK'></th></span></q></dt></tr></i><div id='AA2sK'><tfoot id='AA2sK'></tfoot><dl id='AA2sK'><fieldset id='AA2sK'></fieldset></dl></div>
  • <legend id='AA2sK'><style id='AA2sK'><dir id='AA2sK'><q id='AA2sK'></q></dir></style></legend>

    1. <tfoot id='AA2sK'></tfoot>

      <small id='AA2sK'></small><noframes id='AA2sK'>

        如何在 Android Widget 上实现 Button

        时间:2023-09-08
          <tbody id='zjiCD'></tbody>

        1. <legend id='zjiCD'><style id='zjiCD'><dir id='zjiCD'><q id='zjiCD'></q></dir></style></legend>
            • <bdo id='zjiCD'></bdo><ul id='zjiCD'></ul>

              <small id='zjiCD'></small><noframes id='zjiCD'>

            • <tfoot id='zjiCD'></tfoot>

                1. <i id='zjiCD'><tr id='zjiCD'><dt id='zjiCD'><q id='zjiCD'><span id='zjiCD'><b id='zjiCD'><form id='zjiCD'><ins id='zjiCD'></ins><ul id='zjiCD'></ul><sub id='zjiCD'></sub></form><legend id='zjiCD'></legend><bdo id='zjiCD'><pre id='zjiCD'><center id='zjiCD'></center></pre></bdo></b><th id='zjiCD'></th></span></q></dt></tr></i><div id='zjiCD'><tfoot id='zjiCD'></tfoot><dl id='zjiCD'><fieldset id='zjiCD'></fieldset></dl></div>
                2. 本文介绍了如何在 Android Widget 上实现 Button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我刚刚开始进行 Android 开发,我已经创建了一个不错的小部件,可以在我的主屏幕上显示一些信息.但是,我现在想在我的小部件上实现一个 Button,以更新我的小部件 TextView 中的信息.

                  I am just getting started with Android development and I have created a nice little widget that displays some info on my home screen. However, I now want to implement a Button on my widget that updates the info in my widget TextView.

                  任何人都可以建议如何去做吗?

                  Can anyone advise how to go about doing this?

                  谢谢

                  推荐答案

                  已解决 - 如果您想创建 Button 来更新 Android AppWidget,我可以确认不需要 Activity.

                  Solved - I can confirm that an Activity is NOT needed if you want create a Button to update an Android AppWidget.

                  我已经能够实现我的 AppWidgetProvider 类,以便它在 AndroidManifest.xml 中向广播接收器注册一个 android.appwidget.action.APPWIDGET_UPDATE 意图过滤器,然后触发 AppWidgetProvider 类中的 onUpdate 事件(在然后运行 UpdateService).

                  I have been able to implement my AppWidgetProvider class such that it registers an android.appwidget.action.APPWIDGET_UPDATE intent-filter with the Broadcast receiver in the AndroidManifest.xml, which then fires the onUpdate event in the AppWidgetProvider class (which in turn then runs the UpdateService).

                  <!-- Broadcast Receiver that will process AppWidget updates -->
                  <receiver android:name=".MyWidget" android:label="@string/widget_name">
                     <intent-filter>
                        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                     </intent-filter>
                     <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" />
                  </receiver>
                  

                  我的 AppWidgetProvider 类中的 UpdateService 然后使用 onHandleIntent 运行私有 buildUpdate 方法 - 该方法通过调用 setOnClickPendingIntent 来注册 onClick 事件,如下所示:

                  The UpdateService in my AppWidgetProvider class then uses onHandleIntent to run a private buildUpdate method - which registers the onClick event with a call to setOnClickPendingIntent as follows:

                  // set intent and register onclick
                  Intent i = new Intent(this, MyWidget.class);
                  PendingIntent pi = PendingIntent.getBroadcast(context,0, i,0);
                  updateViews.setOnClickPendingIntent(R.id.update_button,pi);
                  

                  这里是一个工作示例的一些源代码的链接,它显示了如何使用更新按钮来更新 Twitter 小部件:

                  Here is a link to some source code of a working example, which shows how an update button can be used to update a Twitter widget:

                  https://github.com/commonsguy/cw-advandroid/树/b01438e7f0fed8f795ddec4be43066905f03d0cc/AppWidget/TwitterWidget

                  这篇关于如何在 Android Widget 上实现 Button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android 小部件未更新 下一篇:更改 remoteView ImageView 背景

                  相关文章

                3. <tfoot id='50RSl'></tfoot>
                4. <small id='50RSl'></small><noframes id='50RSl'>

                    <i id='50RSl'><tr id='50RSl'><dt id='50RSl'><q id='50RSl'><span id='50RSl'><b id='50RSl'><form id='50RSl'><ins id='50RSl'></ins><ul id='50RSl'></ul><sub id='50RSl'></sub></form><legend id='50RSl'></legend><bdo id='50RSl'><pre id='50RSl'><center id='50RSl'></center></pre></bdo></b><th id='50RSl'></th></span></q></dt></tr></i><div id='50RSl'><tfoot id='50RSl'></tfoot><dl id='50RSl'><fieldset id='50RSl'></fieldset></dl></div>
                    • <bdo id='50RSl'></bdo><ul id='50RSl'></ul>

                    1. <legend id='50RSl'><style id='50RSl'><dir id='50RSl'><q id='50RSl'></q></dir></style></legend>