Skip to main content

Posts

Showing posts with the label button

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:     ...

How to move or put the android button in the middle of the screen

Ques: How to centre buttons on screen horizontally and vertically ? Default Screen: Ans: You need to use a Relative Layout for android GUI in the activity_fullscreen.xml   or whatever you name it. You just need to add the android:layout_centerInParent="true" on your relative layout scope. In default android generate the layout as linear layout for your GUI activity. In that activity you can't use android:layout_centerInParent="true". It will generate warning as --- Invalid layout param in a LinearLayout: layout_centerInParent    activity_fullscreen.xml    /YourProject/res/layout    line 52    Android Lint Problem How?:    Step 1. First open the layout xml from /YourProject/res/layout . Step 2. Change all of the <FrameLayout> ... </FrameLayout> to <RelativeLayout> ... </RelativeLayout> .  Step 3.  Delete default button code porti...