0
메신저마다 두 번째 X 사용 widget_textview 배경을 업데이트하는 핸들러를 삽입하려고하지만 난 모든 곳에서 내가 가지고 코드를 삽입,업데이트 텍스트 뷰 배경은 주기적으로
int i;
if (i==1) {
TextView myTxt = (TextView) findViewById(R.id.widget_textview);
myTxt.setBackgroundResource(R.drawable.pic1);
i++;
}else if(i==2) {
TextView myTxt = (TextView) findViewById(R.id.widget_textview);
myTxt.setBackgroundResource(R.drawable.pic2);
i++;
}else if(i==3) {
TextView myTxt = (TextView) findViewById(R.id.widget_textview);
myTxt.setBackgroundResource(R.drawable.pic1);
i=2;
}else {
i++;
}
내가이 어디를 배치하지 못할 배치 무엇을 어디에서 잘 모릅니다
이 텍스트 뷰
에 오류가 method.This 메소드를 오버라이드 (override)하는) 내 코드 핸들러 클래스 구현에 넣고import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.widget.RemoteViews;
import android.widget.TextView;
public class Widget extends AppWidgetProvider {
private Handler handler = new Handler();
RemoteViews views;
AppWidgetManager appWidgetManager;
ComponentName currentWidget;
Context context;
DateFormat format = new SimpleDateFormat("HH:mm");
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
this.context = context;
this.appWidgetManager = appWidgetManager;
views = new RemoteViews(context.getPackageName(), R.layout.widget);
currentWidget = new ComponentName(context, Widget.class);
handler.removeCallbacks(UpdateWidget);
handler.postDelayed(UpdateWidget, 100);
}
final Runnable UpdateWidget = new Runnable() {
public void run() {
Intent informationIntent = new Intent(context, MainActivity.class);
PendingIntent infoPendingIntent = PendingIntent.getActivity(
context, 0, informationIntent, 0);
views.setOnClickPendingIntent(R.id.Widget, infoPendingIntent);
views.setTextViewText(R.id.widget_textview,
"" + format.format(new Date()));
appWidgetManager.updateAppWidget(currentWidget, views);
handler.postDelayed(UpdateWidget, 1000);
}
};
@Override
public void onDisabled(Context context) {
super.onDisabled(context);
handler.removeCallbacks(UpdateWidget);
}
}
미안하지만 이해할 수없는 부분이 있습니까? 미안 해요 여전히 새로운 – user2033624
처리기 UI를 업데이 트하는 데 사용되는 스레드의 특별한 종류입니다. 같은 Myhandller의 개체를 만들 때 Myhandler handler = new MyHandler(); 을 통해 메시지를 보내 스레드를 업데이트 할 수 있습니다. handler.sendEmptyMessage(); 이것은 배경 업데이트 코드를 넣을 수있는 onHandleMessage() 메소드를 호출합니다. 문제의 첫 번째 코드 스 니펫이 있습니다. 처리기의 메커니즘을 이해하시기 바랍니다. 여전히 처리기가 작동하는 방식을 검색 할 수 있는지 의심 스럽다면 쉽게 코드를 넣을 위치를 결정할 수 있습니다. –
안녕하세요, 도와 주셔서 대단히 감사합니다. – user2033624