button Exclusive Touch - Android User Interface

Android examples for User Interface:Button

Description

button Exclusive Touch

Demo Code


//package com.book2s;
import java.util.ArrayList;

import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class Main {
    public static void buttonExclusiveTouch(View button,
            final ArrayList<Button> arrayBtn) {
        button.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                Button btn = (Button) v;

                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {

                    for (int i = 0; i < arrayBtn.size(); i++) {
                        if (btn == arrayBtn.get(i)) {
                            arrayBtn.get(i).setEnabled(true);
                        } else {
                            arrayBtn.get(i).setEnabled(false);
                        }/*from   w w w  . j a  v  a2 s  . c  o m*/
                    }

                    break;
                }
                case MotionEvent.ACTION_UP: {

                    for (int i = 0; i < arrayBtn.size(); i++) {
                        arrayBtn.get(i).setEnabled(true);
                    }

                    break;
                }
                }
                return false;
            }
        });
    }
}

Related Tutorials