Tuesday, September 3, 2013

How to add button action for multiple button in android

In android it is extreme necessary to use button and do many thing on click or touch of this button.

So how you can do this ?


Ans:   It's pretty simple!

Just find out the -- findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);

It is generated by default in new android sdk. The bold portion is the touch listener for button which is implemented on bellow of your main activity class.
You can do your thing on overriden function OnTouch.


If you want to do it for click and many button here is the way --

findViewById(R.id.dummy_button).setOnClickListener(ButtonListener);

View.OnClickListener ButtonListener = new View.OnClickListener(){

        public void onClick(View view) {
            switch (view.getId()) {

                case R.id.dummy_button:
                      setContentView(R.layout.newwindow);
                      break;
                case R.id.dummy_button1:
                      setContentView(R.layout.newwindow1);
                      break;
                case R.id.dummy_button2:
                      setContentView(R.layout.newwindow2);
                      break;
  
                  }
        }

    };

newwindow,
newwindow1,
newwindow2

are the layouts .

No comments:

Post a Comment

How to enable hotspot in TPG iPhone

 By default, the hotspot does not work on the phone. It will ask you to contact the provider. This video will help you bypass the network ...