点击事件上的android小部件

标签 android android-widget

我已经在 android 中创建了小部件并且它成功地工作了,但是现在我想使用小部件的点击事件,以便我可以从中打开新的 Activity 。

帮帮我

最佳答案

 @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {
    for (int i = 0; i < appWidgetIds.length; i++) {
        int appWidgetId = appWidgetIds[i];

        Intent intent = new Intent(context, TaskManagerActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
        views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

在 widget.xml 中,我有根元素 LinearLayout,ID 为 widget_layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/widget_layout"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:paddingTop="10dip"
          android:paddingLeft="10dip"
          android:orientation="vertical">

关于点击事件上的android小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5347986/

相关文章:

android - 我的Android小部件使启动器崩溃。我该如何调试?

java - 我无法从服务器端套接字读取

android - 使用图层列表不包裹父屏幕的背景可绘制

android - CardView的优缺点

android - 推特可以上传照片吗?如果是,那么如何从 Android 发布或上传照片?

Android 小部件 - 使用带有远程 View 的 setOnClickPendingIntent 未收到 Intent

模拟器中的 Android 小部件

android - 使用 3 个 fragment 创建 Activity

android - 为什么 ListFragment 在没有 ListView 标签的情况下工作?

java - 如何访问我创建的文本文件?