0

メインの RemoteViews にビューを追加しようとしていますが、ガジェットの読み込み中に問題が発生します。これがxmlとコードです。助けていただければ幸いです。

public class WidgetProvider extends AppWidgetProvider {


@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);
    RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_main);
    RemoteViews bookmark = new RemoteViews(context.getPackageName(), R.layout.widget_items);
    updateViews.addView(R.id.view_container,  bookmark);

    appWidgetManager.updateAppWidget(thisWidget, updateViews);

}

}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout_widget"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/widget_4x4_portrait"
>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/view_container"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <!-- New views will be added here at runtime -->
    </LinearLayout>
</LinearLayout>
4

3 に答える 3

1

2.1 にはバグがあることにも注意してください。

appWidgetManager.updateAppWidget(int ID, RemoteViews rv)

動作しません。使用する必要があります

appWidgetManager.updateAppWidget(int [] IDs, RemoteView rv).

私は、特定widget IDの要素を唯一の要素として、単位長の配列を作成しました。

奇妙なことに、両方の方法が で適切に機能し1.6, 2.0, 2.2 and 2.3ます。

non updates で立ち往生している他の人への単なるポインタですappWidgets

于 2011-08-03T05:57:10.767 に答える
0

私はあなたが試すことができると思います:appWidgetManager.getInstance(context).updateAppWidget(thisWidget, updateViews);代わりにof appWidgetManager.updateAppWidget(thisWidget, updateViews);

于 2011-02-24T08:26:38.400 に答える
0

addView 呼び出しに問題があることがわかりました。ウィジェットのメイン レイアウトではなく、新しいビューをそれ自体に追加していました。

于 2011-02-24T08:31:59.213 に答える