Great! Thanks a lot! This finally solves the problem I had a long time
ago (
http://groups.google.com/group/android-developers/browse_frm/thread/5ca8bc78fdaa9e69
) :-)
Peli
On Nov 3, 5:36 am, "Jason Parekh" <[EMAIL PROTECTED]> wrote:
> doh, you're correct, there isn't a way for clients to iterate through the
> items in the menu. :(
>
> at this point, I suggest switching to hard-coding the menu items. if you
> really want to populate the menu via intents, you may have to copy the
> (fixed) addIntentOptions code into a helper class:
>
> public int addIntentOptions(int group, int id, int categoryOrder,
> ComponentName caller,
> Intent[] specifics, Intent intent, int flags, MenuItem[]
> outSpecificItems) {
> PackageManager pm = mContext.getPackageManager();
> final List<ResolveInfo> lri =
> pm.queryIntentActivityOptions(caller, specifics, intent, 0);
> final int N = lri != null ? lri.size() : 0;
>
> if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
> removeGroup(group);
> }
>
> for (int i=0; i<N; i++) {
> final ResolveInfo ri = lri.get(i);
> Intent rintent = new Intent(
> ri.specificIndex < 0 ? intent :
> specifics[ri.specificIndex]);
> rintent.setComponent(new ComponentName(
> ri.activityInfo.applicationInfo.packageName,
> ri.activityInfo.name));
> final MenuItem item = add(group, id, categoryOrder,
> ri.loadLabel(pm))
> .setIcon(ri.loadIcon(pm))
> .setIntent(rintent);
> if (outSpecificItems != null && ri.specificIndex >= 0) {
> outSpecificItems[ri.specificIndex] = item;
> }
> }
>
> return N;
> }
>
> On Sun, Nov 2, 2008 at 11:30 AM, David Given <[EMAIL PROTECTED]> wrote:
> > Jason Parekh wrote:
> > [...]
> > > As an interim solution, you could, in your onCreateOptionsMenu, go
> > > through each menu item and do:
>
> > > Intent intent = item.getIntent();
> > > if (intent != null) item.setIcon(packageManager.getActivityIcon(intent));
>
> > Thanks, that ought to do it --- but I can't seem to find any way of
> > iterating through a Menu and looking at each MenuItem! The only way I
> > can see of getting a MenuItem out of a Menu is to call Menu.findItem();
> > but that needs an id, and they're all likely to be 0. What am I missing?
>
> > --
> > ┌─── dg@cowlark.com ─────http://www.cowlark.com─────
> > │
> > │ ⍎'⎕',∊N⍴⊂S←'←⎕←(3=T)⋎M⋏2=T←⊃+/(V⌽"⊂M),(V⊝"M),(V,⌽V)⌽"(V,V←1⎺1)⊝"⊂M)'
> > │ --- Conway's Game Of Life, in one line of APL
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---