Skip to content

Instantly share code, notes, and snippets.

@kyuucr
Created May 12, 2012 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyuucr/2667195 to your computer and use it in GitHub Desktop.
Save kyuucr/2667195 to your computer and use it in GitHub Desktop.
Android - Hide context menu on certain ListView item.
public class ExampleActivity extends ListActivity {
[...]
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
[...]
registerForContextMenu(mListView);
mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView , View v,int position, long id) {
getListView().getItemAtPosition(position); //check current item with your logic and show or don't show contextMenu
// for example I will show
getListView().showContextMenu(); //to show
return true;
}
});
}
[...]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment