-
Notifications
You must be signed in to change notification settings - Fork 25
Appwidget listview2 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
For adding button on widget,add a view (like ImageView) or any other views supported by app widget in the layout. Then on manifest.xml file,on receiver of appwidget provider <receiver android:name="your.appwidget.receivername" >
<intent-filter>
<action android:name="com.refresh.widget"/>
<!-- Here you can put your own name like com.your.own.name -->
</intent-filter>
</receiver>So this name is essential as when it is received,you have to call your intent for launching the activity.Let's say you have added an ImageView on your layout for widget <ImageView
android:id="@+id/refreshImageView"
android:layout_width="32dip"
android:layout_height="32dip"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:scaleType="fitXY"
android:src="@drawable/your_drawable" />Then on your AppWidgetProvider code public class WidgetProvider extends AppWidgetProvider{
public static String MANIFEST_DEFINED_STRING="com.refresh.widget";
private RemoteViews updateWidgetListView(Context context, int appWidgetId) {
// here you are just setting click listener to your image view
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
final Intent refreshIntent = new Intent(context, WidgetProvider.class);
refreshIntent
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
refreshIntent.setAction(WidgetProvider. MANIFEST_DEFINED_STRING);
final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(
context, appWidgetId, refreshIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.refreshImageView,
refreshPendingIntent);
return remoteViews;
}
@Override
public void onReceive(Context context, Intent intent) {
//here you will receive that onclicklistener
if(MANIFEST_DEFINED_STRING.equals(intent.getAction()){
Intent settingIntent = new Intent(ctx, YourActivity.class);
settingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(settingIntent);
}
}
}This is all you have to do to get to your activity by click of ImageView defined on the App Widget |
|
log cat : manifest appwidget provider: } widget_layout: not working , |
|
i have done some thing like ,is it right way of doing this or not please say that, if not than i wll change my code, this code works fine without any modification anywere in your example, so am going in right or not |
|
hi laaptu, |
|
i solved update issue |
|
Congratulations Pitu On Fri, Dec 13, 2013 at 5:03 PM, pitu notifications@github.com wrote:
|
|
Hi, Does we use Gridview and listview in a single app widget or not.. Thanks.. |
hi i am using this list view,
is it possible to add 1 button on widget, on click of it ,it should open my app, i tried the below code for it, when i use this code ,list view displays empty view, & it forc close some time, how to do that ,please
public class WidgetProvider extends AppWidgetProvider {
xml contain a button btnseemore