我创建了一个简单的小部件,我想在2秒内更改按钮以处理循环。我试着设置widget_button和pbHeaderProgress。但是2秒后,按钮仍然显示,进程条不显示。请帮我!提前致谢! 这是我的代码:
private void updateWidgetPictureAndButtonListener(final Context context) {
Log.e(TAG, "updateWidgetPictureAndButtonListener");
remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_demo);
remoteViews.setTextViewText(R.id.widget_idiom, " ");
remoteViews.setViewVisibility(R.id.widget_button, View.INVISIBLE);
remoteViews.setViewVisibility(R.id.pbHeaderProgress, View.VISIBLE);
final Handler threadHandler = new Handler();
new Thread() {
@Override
public void run() {
threadHandler.postDelayed(new Runnable() {
public void run() {
Log.e(TAG, "okokok");
remoteViews.setViewVisibility(R.id.pbHeaderProgress,
View.INVISIBLE);
remoteViews.setViewVisibility(R.id.widget_button,
View.VISIBLE);
remoteViews.setTextViewText(R.id.widget_idiom,
(CharSequence) getTextToShow());
remoteViews.setOnClickPendingIntent(R.id.widget_button,
MyWidgetProvider
.buildButtonPendingIntent(context));
MyWidgetProvider.pushWidgetUpdate(
context.getApplicationContext(), remoteViews);
}
}, 2000);
}
}.start();
}
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="2sp"
android:background="@drawable/background">
<TextView
android:id="@+id/widget_idiom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5sp"
android:gravity="center"
android:textStyle="italic"
android:textSize="18sp"
/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="right|bottom">
<Button
android:id="@+id/widget_button_setting"
android:layout_width="35sp"
android:layout_height="35sp"
android:background="@drawable/setting"
/>
<Button
android:id="@+id/widget_button_detail"
android:layout_width="35sp"
android:layout_height="35sp"
android:layout_marginLeft="5sp"
android:background="@drawable/detail"
android:layout_toRightOf="@+id/widget_button_setting"
/>
<Button
android:id="@+id/widget_button"
android:layout_width="35sp"
android:layout_height="35sp"
android:layout_marginLeft="5sp"
android:background="@drawable/refresh"
android:layout_toRightOf="@+id/widget_button_detail"
/>
<ProgressBar
android:id="@+id/pbHeaderProgress"
android:layout_width="25sp"
android:layout_height="25sp"
android:layout_marginLeft="10sp"
android:layout_marginTop="5sp"
style="@android:style/Widget.ProgressBar.Small"
android:layout_toRightOf="@+id/widget_button_detail"
android:visibility="gone"
/>
</RelativeLayout>
</LinearLayout>