Listview In App Widget Android
hi friends enter link description here this link to create list view widget for my app, but here i want to add a button below the list view ,which on click will open my app, using
Solution 1:
You need to define how the PendingIntent you are setting will be handled, by overriding the onReceive method inside your provider :
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent.getAction().equals(ACTION_NAME)) {
// Open your activity here.
}
}
If every item in your ListView needs a different extra to help the onReceive create the proper Intent, you can use a FillInIntent for each item of the ListView, in getViewAt :
// Set the onClickFillInIntentfinalIntentfillInIntent=newIntent();
finalBundleextras=newBundle();
extras.putInt(YourWidgetProvider.ACTION_EXTRA_ITEM, event.getId()); // retrieve this in onReceive with intent.getIntExtra(ACTION_EXTRA_ITEM, -1)
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.listview_main_layout, fillInIntent);
return rv;
Also, don't forget to add your Provider and your RemoteViewsService to your Manifest :
<receiverandroid:name="com.example.YourWidgetProvider"android:label="@string/widget_name"><intent-filter><actionandroid:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter><meta-dataandroid:name="android.appwidget.provider"android:resource="@xml/provider_definition_in_xml" /></receiver><serviceandroid:name="com.example.YourRemoteViewsService"android:permission="android.permission.BIND_REMOTEVIEWS"android:exported="false" />
EDIT :
To handle clicks on buttons in the main widget (not in the collection view), it's even easier :
rv.setOnClickPendingIntent(R.id.button_id, PendingIntent.getBroadcast(context, 0,
newIntent(context, YourWidgetProvider.class)
.setAction(ACTION_NAME),
PendingIntent.FLAG_UPDATE_CURRENT));
The ACTION_NAME needs to be different from the name you use for the clicks on the collection view, of course, since it needs to produce a different Intent.
I hope this helps !
Post a Comment for "Listview In App Widget Android"