嗨IM,我已經在很多地方extensivly看了,但我似乎無法弄清楚什麼是錯。基本上我正在調用我的小部件中的pendingintent廣播,併成功捕獲onrecivie方法中的意圖。的Android Appwidget的TextView沒有更新和我的Android小工具一個非常奇怪的問題
然而在onRecive方法,當我嘗試設置使用RemoteViews我的組件中的文本,該文本不更新,也不是所謂的任何錯誤。我附上了我的代碼,任何幫助都會很棒。
感謝, 中號
package com.android.FirstWidget;import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RemoteViews;
public class ExampleAppWidgetProvider extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.e("ds",intent.getAction());
Log.e("f","f");
if(intent.getAction().contains("1")){
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.wid);
views.setTextViewText(R.id.textView1,"heyheyhey");
Log.e("fssss","sssf");
}
super.onReceive(context, intent);
}
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, ExampleAppWidgetProvider.class);
intent.setAction("1");
PendingIntent pendingIntent = PendingIntent.getBroadcast(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.wid);
views.setOnClickPendingIntent(R.id.arrowLeft, pendingIntent);
views.setOnClickPendingIntent(R.id.arrowRight, pendingIntent);
//views.set
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
是的,我得到正確的行動,只有然後我調用views.setTextViewText,但仍然textview將不會更新 – Marius
我是害怕你錯了。你粘貼的代碼的onUpdate方法將不會被任何時間調用,因爲你已經覆蓋onReceive。 onReceive取代所有其他on-methods。此外,我所說的「行動」是這4個行動:http://developer.android.com/guide/topics/appwidgets/index.html#ProviderBroadcasts –