android 根据控件的ID字符串利用反射获取UI控件

int view_id = R.id.class.getField(“xxx”).getInt(null);

View view = findViewById(view_id);

或者:

int view_id = getResources().getIdentifier(“xxx”, “id”, “com.xxx.xxx”);

View view  = findViewById(view_id);


其中xxx为view的id字符串,com.xxx.xxx为工程的包名

    原文作者:yangxi_001
    原文地址: https://blog.csdn.net/yangxi_pekin/article/details/50555418
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞