2010-11-27 16 views
3

上では動作しませんアンドロイドTextView.setTextは、私がテストウィジェットの非常に簡単なAppWidgetProvider持っているシンプルなウィジェット

<LinearLayout 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <TextView 
     android:id="@+id/TextView01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    </TextView> 
</LinearLayout> 

問題があるということをウィジェットはエミュレータ画面に表示されますが、テキストは表示されません。私は何かをつぶしていると確信していますが、それは何かを見つけることができません...

答えて

9

使用するRemoteViewsを設定するのを忘れました。 AppWidgetProviderのコードは次のとおりです。

 

public class Test extends AppWidgetProvider { 

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){ 
     super.onUpdate(context, appWidgetManager, appWidgetIds); 
     RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_layout); 
     views.setTextViewText(R.id.TextView01, "Test message"); 
     appWidgetManager.updateAppWidget(appWidgetIds, views); 
    } 

} 
 
+0

ありがとう!!それは動作します –

+0

ありがとうございます。私も同じ間違いを犯しました。また、あなたのonUpdateメソッドでは、super.onUpdate(context、appWidgetManager、appWidgetIds)を戻す必要があります。一行目に – yancyn

+0

@yancynありがとうございます。私は答えを更新しました。 – Raunak

関連する問題