사용자가 문제가있는 큐 카드 세트를 천천히 회전/반복하는 간단한 위젯을 만들려고합니다 (Windows 전화 라이브 타일과 비슷 함).내 위젯이 업데이트되지 않는 이유는 무엇입니까?
위젯을 만들 수 있으며 "로드 된 항목 없음"과 같은 말을 설정 한 기본 텍스트가 표시되며 콜백이 표시되지만 위젯 텍스트는 업데이트되지 않습니다.
스택 오버플로뿐 아니라 안드로이드 도큐를 샅샅이 뒤졌지만 대답을 찾을 수 없습니다. 아마도 내 ComponentName이 올바르지 않을 것 같아서 위젯 관리자의 위젯 배열을 가져 와서 반복 해 보았습니다. 그것은 위젯의 목록을 얻을, 그래서 올바른 것 같습니다 ...
내가 뭘 잘못하고있어?
많은 감사합니다, 내 매니페스트 XML에 돼지
public class MistakeArchiveWidgetProvider extends AppWidgetProvider
{
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds)
{
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 60000);
// When the widget is clicked, launch the app.
for (int i = 0; i < appWidgetIds.length; i++)
{
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, QuizActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.mistake_archive_widget);
views.setOnClickPendingIntent(R.id.STATIC_CUE, pendingIntent);
views.setOnClickPendingIntent(R.id.STATIC_ANSWER, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
private class MyTime extends TimerTask
{
public MyTime(Context context, AppWidgetManager appWidgetManager)
{
this.m_appWidgetManager = appWidgetManager;
m_remoteViews = new RemoteViews(context.getPackageName(),
R.layout.mistake_archive_widget);
m_componentName = new ComponentName(context, MistakeArchiveWidgetProvider.class);
m_context = context;
}
@Override
public void run()
{
MistakeArchive archive = new MistakeArchive();
if(archive.restoreState(m_context))
{
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(m_context);
int activeIndex = prefs.getInt(
MyPrefs.PREFKEY_ACTIVE_MISTAKE_ARCHIVE_HASH_INDEX, 0);
activeIndex++;
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(MyPrefs.PREFKEY_ACTIVE_MISTAKE_ARCHIVE_HASH_INDEX,
activeIndex);
editor.commit();
CueLine cueLine = archive.getMistake(activeIndex);
if(cueLine != null)
{
m_remoteViews.setTextViewText(R.id.STATIC_CUE, cueLine.GetCue());
m_remoteViews.setViewVisibility(R.id.STATIC_CUE, View.VISIBLE);
m_remoteViews.setTextViewText(R.id.STATIC_ANSWER, cueLine.GetAnswer());
int[] appWidgetIds = m_appWidgetManager.getAppWidgetIds(m_componentName);
for (int i = 0; i < appWidgetIds.length; i++)
{
m_appWidgetManager.updateAppWidget(i, m_remoteViews);
}
}
}
}
RemoteViews m_remoteViews;
AppWidgetManager m_appWidgetManager;
ComponentName m_componentName;
Context m_context;
}
}
난이 :
<receiver android:name="myApp.MistakeArchiveWidgetProvider" android:label="@string/IDST_APP_NAME">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/mistake_archive_widget_provider" />
</receiver>
mistake_archive_widget_provider.xml :
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="50dip"
android:minHeight="50dip"
android:updatePeriodMillis="10000"
android:initialLayout="@layout/mistake_archive_widget"
/>
mistake_archive_widget.xml :
,536,<?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="fill_parent"
android:orientation="vertical"
android:background="@drawable/widget_background"
>
<TextView
android:id="@+id/STATIC_CUE"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_weight="1"
android:textStyle="bold"
android:visibility="gone"
android:text=""
/>
<TextView android:id="@+id/STATIC_ANSWER"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_weight="1"
android:text="@string/IDST_NO_CUES_LOADED"
/>
</LinearLayout>
클릭 이벤트를 복용 여부를 위젯? –
예 click 이벤트는 작동하지만 업데이트는 작동하지 않습니다. – swinefeaster
위젯을 업데이트하기 위해 맞춤 수신기를 등록했는지 확인하십시오. –