Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate ViewFlipper's Child View when ViewFlipper is as Widget
    primarykey
    data
    text
    <p>I have problems about updating child view in ViewFlipper when I use the ViewFlipper as the Widget.</p> <p>Here are layout for Widgets:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Widget Title" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;Button android:id="@+id/refresh_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="Refresh" /&gt; &lt;ViewFlipper android:id="@+id/viewflipper" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/refresh_button" android:autoStart="true" android:inAnimation="@anim/in_from_bottom" android:outAnimation="@anim/out_from_top" android:flipInterval="10000" &gt; &lt;TextView android:name="@+id/test1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF00FF" android:text="test1" /&gt; &lt;TextView android:name="@+id/test2" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00FF00" android:text="test2" /&gt; &lt;/ViewFlipper&gt; </code></pre> <p></p> <p>And Here is the AppWidgetProvider:</p> <pre><code>package com.example.filperwidget; 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.widget.RemoteViews; import android.widget.Toast; public class FilperWidgetProvider extends AppWidgetProvider { private static final String TAG = FilperWidgetProvider.class.getSimpleName(); private static final String REFRESH_ACTION = "com.example.fliperwidget.REFRESH"; private RemoteViews mRemoteViews; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int i = 0; i &lt; appWidgetIds.length; i++) { int widgetId = appWidgetIds[i]; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); remoteViews.setTextViewText(R.id.test1, "flipper"); initRefreshButton(context, remoteViews, widgetId); mRemoteViews = remoteViews; appWidgetManager.updateAppWidget(widgetId, remoteViews); } super.onUpdate(context, appWidgetManager, appWidgetIds); } private void initRefreshButton(Context context, RemoteViews remoteViews, int appWidgetId) { // Bind the click intent for the refresh button on the widget final Intent refreshIntent = new Intent(context, FilperWidgetProvider.class); refreshIntent.setAction(FilperWidgetProvider.REFRESH_ACTION); refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast( context, 0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.refresh_button, refreshPendingIntent); } @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(REFRESH_ACTION)) { Toast.makeText(context, "Refreash is clicked", Toast.LENGTH_SHORT) .show(); RemoteViews remoteViews = mRemoteViews; if (mRemoteViews == null) { WidgetLog.d(TAG, "mRemoteViews == null"); remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); } final ComponentName cn = new ComponentName(context, FilperWidgetProvider.class); AppWidgetManager appWidgetManager = AppWidgetManager .getInstance(context); // appWidgetManager.updateAppWidget(appWidgetId, views); // remoteViews.setTextViewText(R.id.test1, "Click Test"); remoteViews.setCharSequence(R.id.test1, "setText", "Test Test"); remoteViews.setTextViewText(R.id.test2, "Click Test2"); remoteViews.setTextViewText(R.id.title, "Test"); int id = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); remoteViews.showNext(R.id.viewflipper); appWidgetManager.updateAppWidget(id, remoteViews); appWidgetManager.updateAppWidget(cn, remoteViews); } super.onReceive(context, intent); } } </code></pre> <p>As you can see, when I update the Widget Title, it can work. But When I want to update the subView of Flipper (Text1/Text2), It doesn't work-The text is not changed. The <code>showNext()</code> also work correctly. So anyone can help for that? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload