I'm fairly new to android app development, and I've been playing around with context menus. The info on the developer site is very straightforward, and I can make it work just fine. After looking at it though I just wanted to make a simple context menu show up from a long press on a blank layout. I've tried all manner of things, but I can't seem to figure it out. Is android limited as to which types of views you can call a context menu from?
Here's my current version, which is DRASTICALLY different than how I started with it. This causes the emulator to crash as soon as the the app starts. I know this should be fairly simple, but I'm at a loss. Any help would be great. Thanks!
Here's my current version, which is DRASTICALLY different than how I started with it. This causes the emulator to crash as soon as the the app starts. I know this should be fairly simple, but I'm at a loss. Any help would be great. Thanks!
Code:
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
public class Menus extends Activity {
/** Called when the activity is first created. **/
View.OnCreateContextMenuListener contextListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View myView = getCurrentFocus();
registerForContextMenu(myView);
contextListener = new View.OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.cmenu, menu);
}
};
}
}