Dynamic Menu in Android?
<p>I need to show menu at the time of button Click.But I am not able to display the menu . My code is below. Can anyone tell me what is wrong in my code ??? Thanks in Advance !!!</p>

<p>Code :</p>

<pre><code>import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class DynamicMenu extends Activity {
/** Called when the activity is first created. */
private Context context;
Button btnMenu;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;


    LinearLayout llay = new LinearLayout(context);

    btnMenu = new Button(context);
    btnMenu.setText("Show Menu");


    llay.addView(btnMenu);

    setContentView(llay);

    registerForContextMenu(btnMenu);

}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenu.ContextMenuInfo menuInfo) {
    Menu m_menu = menu;
    m_menu.add(0, 1, 0, "Settings");
    m_menu.add(0, 2, 0, "About");
    m_menu.add(0, 3, 0, "Exit");
}

}
</code></pre>
