Android widget ListView项目单击不起作用

Android widget ListView项目单击不起作用,android,android-service,android-widget,android-pendingintent,remoteview,Android,Android Service,Android Widget,Android Pendingintent,Remoteview,因此,我正在尝试设置一个带有列表的小部件,但单击不起作用,因此我理解要做到这一点,我需要一个模板挂起意图,因为单个项目不能有自己的,然后使用填充意图添加到挂起意图模板,我已将所有这些添加到我的应用程序中,但它仍然不起作用,我遵循了建议,但当我点击一个项目时,它只是突出显示,表明它已注册点击,并且什么也不做,但我在 logcat 这是我的代码,我的onUpdate方法调用一个静态更新小部件方法,该方法定义了我的模板挂起意图和onReceive方法 AppWidgetProvider public

因此,我正在尝试设置一个带有列表的小部件,但单击不起作用,因此我理解要做到这一点,我需要一个模板挂起意图,因为单个项目不能有自己的,然后使用填充意图添加到挂起意图模板,我已将所有这些添加到我的应用程序中,但它仍然不起作用,我遵循了建议,但当我点击一个项目时,它只是突出显示,表明它已注册点击,并且什么也不做,但我在 logcat

这是我的代码,我的onUpdate方法调用一个静态更新小部件方法,该方法定义了我的模板挂起意图和onReceive方法

AppWidgetProvider

public class MessageMeAppWidget extends AppWidgetProvider {
private static final String TAG = "MsgMeWdgt";

@Override
public void onReceive(Context context, Intent intent) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (intent.getAction().equals(Constants.LAUNCH_ACTIVITY)) {
        int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);

        //String recipientId =  intent.getStringExtra(Constants.FS_ID);
        //String recipientName =  intent.getStringExtra(Constants.FS_NAME);

        Intent i = new Intent(context, MessageListActivity.class);
        Bundle b = new Bundle();
        //b.putString(Constants.FS_ID, recipientId);
        //b.putString(Constants.FS_ID, recipientName);
        i.putExtras(b);
        Bundle bundle = intent.getExtras();
        String toastText = "position is " + bundle.getInt(Constants.LAUNCH_ACTIVITY);
        Toast.makeText(context,toastText,Toast.LENGTH_SHORT).show();
        //context.startActivity(i);
    }else if(intent.getAction().equals(Constants.DONT_LAUNCH_ACTIVITY)){
        //Toast.makeText(context,"",Toast.LENGTH_SHORT).show();
    }
    super.onReceive(context, intent);
}

public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                                   int appWidgetId) {

    SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SHARED_PREFS,Context.MODE_PRIVATE);
    boolean userSignedIn = sharedPreferences.getBoolean(Constants.SIGNED_IN, false);
    if (userSignedIn){
        //move everything in here after i know its working
    }
    Intent intent = new Intent(context, MessagingService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_list_view);
    //populates data
    remoteViews.setRemoteAdapter(R.id.widget_list,intent);
    //remoteViews.setRemoteAdapter(appWidgetId, R.id.widget_list, intent);
    remoteViews.setEmptyView(R.id.widget_list,R.id.empty);

    Intent launchIntent = new Intent(context, WidgetAdapter.class);
    launchIntent.setAction(Constants.LAUNCH_ACTIVITY);
    launchIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    PendingIntent launchPendingIntent = PendingIntent.getBroadcast(context, 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    remoteViews.setPendingIntentTemplate(R.id.widget_list, launchPendingIntent);
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);

}

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // There may be multiple widgets active, so update all of them
           Log.d(TAG,"on update");
    for (int appWidgetId : appWidgetIds) {
        updateAppWidget(context, appWidgetManager, appWidgetId);
    }
}
那么我的widget服务是标准的

public class MessagingService extends RemoteViewsService {
private String TAG = "MsgSrvc";
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
    Log.d(TAG,"item clicked");
    return new WidgetAdapter(this.getApplicationContext(), intent);
  }
}
然后在我的小部件适配器的getViewAt方法中,我像这样填充我的填充意图

    Bundle extras = new Bundle();
    extras.putInt(Constants.LAUNCH_ACTIVITY, position);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtras(extras);
    remoteViews.setOnClickFillInIntent(R.id.holder, fillInIntent);
在我的清单中,我正在注册我的小部件服务和接收者

<receiver android:name="com.sealstudios.aimessage.MessageMeAppWidget">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/message_me_app_widget_info" />
    </receiver>

    <service android:name=".MessagingService"
        android:permission="android.permission.BIND_REMOTEVIEWS" />


感谢任何帮助

我修复了这个问题,因为它的意图是指向错误的类,所以

Intent launchIntent = new Intent(context, WidgetAdapter.class); 
应该是

Intent launchIntent = new Intent(context, MessageMeAppWidget.class);
Intent launchIntent = new Intent(context, MessageMeAppWidget.class);