Convert motion Event Action To String - Android android.view

Android examples for android.view:MotionEvent

Description

Convert motion Event Action To String

Demo Code


//package com.java2s;

import android.view.MotionEvent;

public class Main {
    private static String motionEventActionToString(int action) {
        java.lang.reflect.Field fields[] = MotionEvent.class
                .getDeclaredFields();//from  ww  w . j  a  va 2s .co  m
        for (int iField = 0; iField < fields.length; ++iField) {
            java.lang.reflect.Field field = fields[iField];
            if (field.getType() == int.class
                    && field.getName().startsWith("ACTION_")) {
                try {
                    if (field.getInt(null) == action)
                        return field.getName();
                } catch (IllegalAccessException e) {
                }
            }
        }
        return "(action " + action + " ???)";
    }
}

Related Tutorials