Advertisement
aurko96

Android code

Nov 13th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. package com.example.user.myfirstandroid;
  2.  
  3.  
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.view.MotionEvent;
  7. import android.view.View;
  8. import android.widget.Button;
  9.  
  10. import static android.view.View.INVISIBLE;
  11. import static android.view.View.VISIBLE;
  12.  
  13. public class MainActivity extends AppCompatActivity{
  14.  
  15.  
  16.    private Button button,button2;
  17.     @Override
  18.     public void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_main);
  21.         button = (Button) findViewById(R.id.button);
  22.         button2 = (Button) findViewById(R.id.button2);
  23.         //final Button button2 = new Button(getApplicationContext());
  24.         button2.setVisibility(INVISIBLE);
  25.         View.OnTouchListener abc = new View.OnTouchListener() {
  26.             @Override
  27.             public boolean onTouch(View view, MotionEvent event) {
  28.                 switch(event.getAction()) {
  29.                     case MotionEvent.ACTION_DOWN:
  30.                         // PRESSED
  31.                         button2.setVisibility(VISIBLE);
  32.                         button.setVisibility(INVISIBLE);
  33.                         return true; // if you want to handle the touch event
  34.                     case MotionEvent.ACTION_UP:
  35.                         // RELEASED
  36.                        // button.setVisibility(INVISIBLE);
  37.                         return true; // if you want to handle the touch event
  38.                 }
  39.                 return false;
  40.             }
  41.  
  42.         };
  43.         button.setOnTouchListener(abc);
  44.  
  45.  
  46.  
  47.         View.OnTouchListener def = new View.OnTouchListener() {
  48.             @Override
  49.             public boolean onTouch(View view, MotionEvent event) {
  50.                 switch(event.getAction()) {
  51.                     case MotionEvent.ACTION_DOWN:
  52.                         // PRESSED
  53.                         button.setVisibility(VISIBLE);
  54.                         button2.setVisibility(INVISIBLE);
  55.                         return true; // if you want to handle the touch event
  56.                     case MotionEvent.ACTION_UP:
  57.                         // RELEASED
  58.                         //button2.setVisibility(INVISIBLE);
  59.                         return true; // if you want to handle the touch event
  60.                 }
  61.                 return false;
  62.             }
  63.  
  64.         };
  65.         button2.setOnTouchListener(def);
  66.  
  67.        
  68.         /*button2.setOnClickListener(new OnClickListener() {
  69.             @Override
  70.             public void onClick(View view) {
  71.                 button2.setVisibility(INVISIBLE);
  72.                 button.setVisibility(VISIBLE);
  73.             }
  74.         });*/
  75.        
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement