Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.user.myfirstandroid;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.MotionEvent;
- import android.view.View;
- import android.widget.Button;
- import static android.view.View.INVISIBLE;
- import static android.view.View.VISIBLE;
- public class MainActivity extends AppCompatActivity{
- private Button button,button2;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- button = (Button) findViewById(R.id.button);
- button2 = (Button) findViewById(R.id.button2);
- //final Button button2 = new Button(getApplicationContext());
- button2.setVisibility(INVISIBLE);
- View.OnTouchListener abc = new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent event) {
- switch(event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- // PRESSED
- button2.setVisibility(VISIBLE);
- button.setVisibility(INVISIBLE);
- return true; // if you want to handle the touch event
- case MotionEvent.ACTION_UP:
- // RELEASED
- // button.setVisibility(INVISIBLE);
- return true; // if you want to handle the touch event
- }
- return false;
- }
- };
- button.setOnTouchListener(abc);
- View.OnTouchListener def = new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent event) {
- switch(event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- // PRESSED
- button.setVisibility(VISIBLE);
- button2.setVisibility(INVISIBLE);
- return true; // if you want to handle the touch event
- case MotionEvent.ACTION_UP:
- // RELEASED
- //button2.setVisibility(INVISIBLE);
- return true; // if you want to handle the touch event
- }
- return false;
- }
- };
- button2.setOnTouchListener(def);
- /*button2.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- button2.setVisibility(INVISIBLE);
- button.setVisibility(VISIBLE);
- }
- });*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement