Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old November 15th, 2013, 05:42 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Sep 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Changing layout when button clicked on widget

hi,
I have a widget. What I want to do is to change a layout when button is clicked.

This is what I'm doing:

public class MainWidgetProvider extends AppWidgetProvider {

public static String ACTION_MENU_CLICKED = "MenuClicked";

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

Intent intent = new Intent(context, MainWidgetProvider.class);
intent.setAction(ACTION_MENU_CLICKED);

PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main_widget_layout);

views.setOnClickPendingIntent(R.id.button2, pendingIntent);
}


@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);

if (intent.getAction().equals(ACTION_MENU_CLICKED)) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main_widget_layout);

views.setViewVisibility(R.id.layout1,View.INVISIBL E);
views.setViewVisibility(R.id.layout2,View.VISIBLE) ;

final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGE T_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
appWidgetManager.updateAppWidget(appWidgetId, views);

}
}
}

Where is my problem? The code as it now does nothing.

oleg88 is offline  
Reply With Quote
sponsored links
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:36 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.