Maybe use android.widget.ToggleButton?


On Saturday, February 23, 2013 12:11:58 AM UTC-6, abhay_401 wrote:
>
> Hi,
>
> Actually I want something like, toggle button type widget. When the 
> user clicks on widget i want to change the widget  
> background or layout so that user will know the on/off condition.
>
> On Sat, Feb 23, 2013 at 10:11 AM, Abhilash baddam <
> [email protected] <javascript:>> wrote:
>
>> Hi
>> I am trying to change the layout on click of widget(linear layout) but 
>> it's not happening, I am not getting  where i am doing mistake, here is the 
>> code snippet,
>> Help me out.
>>
>>     public class HelloWidget extends AppWidgetProvider {
>>     public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
>>     private static final int REQUEST_CODE_ONE = 10;
>>     private boolean check = false;
>>     private static Context mContext;
>>     static int[] widgetId;
>>     RemoteViews remoteViews;
>>     @Override
>>     public void onUpdate(Context context, AppWidgetManager 
>> appWidgetManager,
>>             int[] appWidgetIds) {
>>         // TODO Auto-generated method stub
>>         System.out.println("ON UPDATE");
>>         //mContext = context;
>>         //widgetId = appWidgetIds;
>>         remoteViews = new RemoteViews(context.getPackageName(),
>>                 R.layout.testwidget);
>>         Intent active = new Intent(context, HelloWidget.class);
>>         active.setAction(ACTION_WIDGET_RECEIVER);
>>         active.putExtra("widgetids", appWidgetIds);
>>         PendingIntent actionPendingIntent = 
>> PendingIntent.getBroadcast(context,
>>                 REQUEST_CODE_ONE, active, 0);
>>         remoteViews.setOnClickPendingIntent(R.id.ll, actionPendingIntent);
>>         appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
>>     }
>>
>>     @Override
>>     public void onReceive(Context context, Intent intent) {
>>         // TODO Auto-generated method stub
>>          System.out.println("ONRECEIVEEEEEEEEE");
>>         final String action = intent.getAction();
>>         System.out.println("ACTION "+action);
>>         if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
>>             final int appWidgetId = intent.getExtras().getInt(
>>                     AppWidgetManager.EXTRA_APPWIDGET_ID,
>>                     AppWidgetManager.INVALID_APPWIDGET_ID);
>>             if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
>>                 this.onDeleted(context, new int[] { appWidgetId });
>>             }
>>         }else{
>>             System.out.println("HERE I AM");
>>             if(!check){
>>                 check = true;
>>             }else{
>>                 check = false;
>>             }
>>             updateWidget(context);
>>         }
>>     }
>>     
>>     private void updateWidget(Context context){
>>         System.out.println("INSIDE MY UPDATE WIDGET");
>>         //RemoteViews views = null;
>>         System.out.println(" PACK ANEM "+context.getPackageName());
>>         //System.out.println(" ");
>>         if(check){
>>             System.out.println(" Inside if");
>>             remoteViews = new RemoteViews(context.getPackageName(),
>>                         R.layout.hellowidget);
>>         }else{
>>             System.out.println(" Inside else");
>>             remoteViews = new RemoteViews(context.getPackageName(),
>>                         R.layout.testwidget);
>>         }
>>         ComponentName localComponentName = new ComponentName(context, 
>> HelloWidget.class);
>>         
>> AppWidgetManager.getInstance(context).updateAppWidget(localComponentName, 
>> remoteViews);
>>         //AppWidgetManager mgr = AppWidgetManager.getInstance(context);
>>         //mgr.updateAppWidget(widgetId, remoteViews);
>>     }
>> }
>>
>> this is my hellowidget.xml:
>>
>> <?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="@layout/myshape">
>>
>>     <Button
>>         android:id="@+id/tv"
>>         android:layout_width="fill_parent"
>>         android:layout_height="fill_parent"
>>         android:text="@string/app_name" 
>>         android:gravity="center_vertical|center_horizontal"
>>         />
>>
>> </LinearLayout>
>>   
>>     
>>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to