1

以下代码创建一个小部件并将其添加到我的布局中。但无论是什么监听器'OnLongClick' 或'OnFocus' ......我添加到'hostView' 没有人会触发。'hostView' 也会忽略 'setFocusable(false)'。有谁知道如何从主机视图向小部件添加侦听器?

public void createWidget(Intent data) {
    Bundle extras = data.getExtras();
    int appWidgetId = extras
            .getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager
            .getAppWidgetInfo(appWidgetId);
    final AppWidgetHostView hostView = mAppWidgetHost.createView(this,
            appWidgetId, appWidgetInfo);
    hostView.setAppWidget(appWidgetId, appWidgetInfo);
    ((LinearLayout) findViewById(R.id.widgetHolder)).addView(hostView);
    ((ImageButton) findViewById(R.id.bApps)).requestFocus();
}
4

0 回答 0