0

I have a Menu object.

this has an Arrraylist<MenuItemImpl> to "mItems" name. this is hide.

(MenuItemImpl) is a hide & protected class. See class (here)

Now ,how i can get this arraylist.

@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
    { 

      List<Field> list = getAllFields(menu);
      for(Field f: list)
      {
          if(f.getName().equals("mItems"))
           {
             f.setAccessible(true);
             return f.get( /* here */ );   // <<--- I use new Arraylist<Object> , but get exception
           }
       }
   }

public static List<Field> getAllFields(Object obj)
    {
        List<Field> res = new ArrayList<>();
        res.addAll(Arrays.asList(obj.getClass().getDeclaredFields()));
    if (obj.getClass().getSuperclass() != null)
    {
        res.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields()));
    }

    return res;
}

in f.get() I use new Arraylist<Object> , but get exception

Please help me.Tanks

1 Answer 1

1

oh, I get my answer.

for(Field f: list)
      {
          if(f.getName().equals("mItems"))
           {
             f.setAccessible(true);
             return f.get(menu);
           }
       }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.