views:

1977

answers:

3

I have a Listview with a ContextMenu, but when I setIcon for ContextMenu look like it doesn't work

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

    super.onCreateContextMenu(menu, v, menuInfo);
    menu.add(0, DELETE_ID, 0, R.string.context_menu_favorite)
     .setIcon(android.R.drawable.btn_star);     
}
+3  A: 

Context menus do not support icons.

Note: Context menu items do not support icons or shortcut keys.

CommonsWare
This is exactly in android document. thanks!
Dennie
+1  A: 

While the Android API does not allow for Icons in Context menus you can see many places where Android is using them. Long pressing your home screen is one good example.

I took the time to dig through the Launcher and AnyCut source and found that Google is using their own custom class that extends a BaseAdapter along with their own custom layout.

I was able to copy their class and layout almost exactly and use it in my own app to accomplish. The class if you want to search for it is called AddAdapter.java.

Enjoy!

pcm2a
About the AddAdapter class, is this the one that you were able to copy or the one that you found withoud modification? I was wondering if you could share this oneThanks a lot!
Curro
+1  A: 

Below tutorial show how to create Context Menu with Icon supported:

http://android-demo.blogspot.com/2010/09/android-context-menu-with-icon.html

taniGroup