Android examples for User Interface:View Property
get All Pair Methods from View Class
//package com.java2s; import android.view.View; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.HashSet; import java.util.Set; public class Main { public static Set<String> getAllPairMethods(Class<? extends View> clazz) { Method[] methods = clazz.getMethods(); Set<String> getter = new HashSet<>(); Set<String> setter = new HashSet<>(); for (Method method : methods) { if (Modifier.isPublic(method.getModifiers())) { if (method.getParameterTypes().length == 1) { Class param = method.getParameterTypes()[0]; if (method.getName().startsWith("set")) { if (param.isPrimitive() || CharSequence.class .isAssignableFrom(param.getClass()) && !param.getSimpleName().equals("Object")) { //LogUtil.e("Reflect", "Setter: " + method.getName() + "," + param.getSimpleName()); setter.add(method.getName().substring(3)); }//from w w w. j a va 2 s . com } } else if (method.getParameterTypes().length == 0) { if (method.getName().startsWith("get")) { if (method.getReturnType().isPrimitive() || method.getReturnType().isAssignableFrom( CharSequence.class) && !method.getReturnType().getSimpleName() .equals("Object")) { //LogUtil.e("Reflect", "Getter: " + method.getName() + "," + method.getReturnType().getSimpleName()); getter.add(method.getName().substring(3)); } } } } } getter.retainAll(setter); return getter; } }