Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在小部件开发中更新我的android应用程序小部件列表视图_Android_Android Intent_Android Widget_Widget - Fatal编程技术网

如何在小部件开发中更新我的android应用程序小部件列表视图

如何在小部件开发中更新我的android应用程序小部件列表视图,android,android-intent,android-widget,widget,Android,Android Intent,Android Widget,Widget,我是android应用程序小部件开发新手。 我想为我的应用程序创建应用程序小部件 我在我的应用程序小部件开发中使用了这个Github项目 要求: 1。我的listview的数据是动态的,这意味着数据与我的应用程序数据同步。如果应用程序数据发生更改,则自动更新/删除小部件数据 我已经搜索了很多天了,但是没有找到任何解决方案 如果任何人有解决方案,请提供帮助。@Harshid此代码可以帮助您。请查看并尝试此代码 package com.automatic.widget; import andro

我是android应用程序小部件开发新手。 我想为我的应用程序创建应用程序小部件

我在我的应用程序小部件开发中使用了这个Github项目

要求:

1。我的listview的数据是动态的,这意味着数据与我的应用程序数据同步。如果应用程序数据发生更改,则自动更新/删除小部件数据

我已经搜索了很多天了,但是没有找到任何解决方案


如果任何人有解决方案,请提供帮助。

@Harshid此代码可以帮助您。请查看并尝试此代码

package com.automatic.widget;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class Widget extends AppWidgetProvider {

private static final String SYNC_CLICKED    = "automaticWidgetSyncButtonClick";

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    RemoteViews remoteViews;
    ComponentName watchWidget;

    remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    watchWidget = new ComponentName(context, Widget.class);

    remoteViews.setOnClickPendingIntent(R.id.sync_button, getPendingSelfIntent(context, SYNC_CLICKED));
    appWidgetManager.updateAppWidget(watchWidget, remoteViews);
}

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    super.onReceive(context, intent);

    if (SYNC_CLICKED.equals(intent.getAction())) {

        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

        RemoteViews remoteViews;
        ComponentName watchWidget;

        remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        watchWidget = new ComponentName(context, Widget.class);

        remoteViews.setTextViewText(R.id.sync_button, "TESTING");

        appWidgetManager.updateAppWidget(watchWidget, remoteViews);

    }
}

protected PendingIntent getPendingSelfIntent(Context context, String action) {
    Intent intent = new Intent(context, getClass());
    intent.setAction(action);
    return PendingIntent.getBroadcast(context, 0, intent, 0);
}
}