Click here to Skip to main content
13,297,048 members (51,726 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Panel pnl;
    public void onCreate(Bundle savedInstanceState) {
        pnl = new Panel(this);
public boolean onPrepareOptionsMenu (Menu menu) {
        text_enter = menu.getItem(1);
        text_enter.setOnMenuItemClickListener(new OnMenuItemClickListener()
            public boolean onMenuItemClick(MenuItem clickedItem)
//Need to write something here to add button or other element programatically
                return true;
        return true;
   class Panel extends SurfaceView implements SurfaceHolder.Callback {
	   private TutorialThread _thread;
        public Panel(Context context) {
            _thread = new TutorialThread(getHolder(), this);
        public boolean onTouchEvent(MotionEvent event) {
            synchronized (_thread.getSurfaceHolder()) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                	if(menu_action == "traffic")
                		menu_action = "";
                		return true;
                    initial_x = event.getX();
                    initial_y = event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                return true;
        public void onDraw(Canvas canvas) {
            Bitmap img;
            GraphicObject.Coordinates cords;
            cords = image.getCoordinates();
            img = image.getGraphic();
            canvas.drawBitmap(img, cords.getX(), cords.getY(), null);
             catch(Exception x){
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            // TODO Auto-generated method stub
        public void surfaceCreated(SurfaceHolder holder) {
        public void surfaceDestroyed(SurfaceHolder holder) {
            // simply copied from sample application LunarLander:
            // we have to tell thread to shut down & wait for it to finish, or else
            // it might touch the Surface after we return and explode
            boolean retry = true;
            while (retry) {
                try {
                    retry = false;
                } catch (InterruptedException e) {
                    // we will try it again and again...

Please, help.
Posted 11-Dec-12 6:32am
Yvar Birx 11-Dec-12 12:01pm
What is your problem ?
halabella 11-Dec-12 15:21pm
I need to add a button and editbox by "onMenuItemClick"

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

DO not add button - create the button right away and set it visible(false).
Then, when the onMenuItemClick is called, set the button visible(true).

* not granted that visible(boolean) exists in Android programming, but I guess so. It might be named different though. Please check that out yourself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100