发布于2021-03-13 14:02 阅读(774) 评论(0) 点赞(10) 收藏(3)
在线Java编译器:https://tool.lu/coderunner/
1、复制进去的化有绑定控件代码就行,其他非绑定控件代码会过滤掉。
2、在线Java运行编译器里直接不能复制,不然会出现String格式不符异常,可以用word文档处理(回车,前置空格即可);
例:@BindView(R2.id.middlegiftLayout)View mMiddleGiftLayout;@BindView(R2.id.middlegiftHead)ImageView mMiddleGiftHead;@BindView(R2.id.middleSendName)TextView mMiddleSendName;@BindView(R2.id.middleGetName)TextView mMiddleGetName;@BindView(R2.id.middleText)TextView mMiddleText;@BindView(R2.id.middleGiftName)TextView mMiddleGiftName;
3、可以直接在Android测试类里复制运行使用,复制到s对象里就行,里面会自动转换string未规范形式,然后测试运行打印出来的就是了。
class Untitled {
public static void main(String[] args) {
String s="@BindView(R2.id.simple_room)\n" +
" RoundedImageView simple_room;\n" +
" @BindView(R2.id.viewpager)\n" +
" ViewPager mViewPager;\n" +
" BottomAdapter mAdapter;\n" +
"\n" +
" @BindView(R2.id.room_type)\n" +
" TextView room_type;\n" +
" @BindView(R2.id.room_name)\n" +
" TextView room_name;\n" +
" @BindView(R2.id.online_room)\n" +
" TextView online_room;\n" +
" @BindView(R2.id.exmine)\n" +
" ImageView exmine;\n" +
" @BindView(R2.id.collect)\n" +
" TextView mCollect;\n" +
" @BindView(R2.id.roomId)\n" +
" TextView mRoomId;";//需要转换的内容放这
s=s.replaceAll("\\n","");
s=s.replaceAll(" ","");
String[] t=s.split(";");
StringBuilder f= new StringBuilder();
for (String value : t) {
if (value.contains("R2.id.")) {
String id = value.replaceAll("@BindView\\(R2.id.", "").split("\\)")[0];
String name = value.split("\\)")[1].split(" ")[1];
f.append(name).append("=findViewById(R.id.").append(id).append(");\n");
}
}
System.out.println(f);
}
}
可以放回类型,应对需要返回类型的情况。
class Untitled {
public static void main(String[] args) {
String s="@BindView(R2.id.queue_list2)\n" +
" RecyclerView queue_list2;\n" +
" @BindView(R2.id.typePrivate)\n" +
" RelativeLayout mPrivateLayout;\n" +
"\n" +
" @BindView(R2.id.queue_list)\n" +
" RecyclerView queue_list;\n" +
"\n" +
" @BindView(R2.id.equipment_linyout)\n" +
" LinearLayout equipment_linyout;\n" +
" @BindView(R2.id.send_linyout)\n" +
" LinearLayout send_linyout;\n" +
" @BindView(R2.id.rankLayout)\n" +
" View mRankLayout;\n" +
" @BindView(R2.id.go_back)\n" +
" ImageView go_back;\n" +
" @BindView(R2.id.edt_input_text)\n" +
" EditText edt_input_text;\n" +
"\n" +
" @BindView(R2.id.egg)\n" +
" ImageView mEgg;\n" +
" @BindView(R2.id.middle_gift)\n" +
" View MiddleGift;\n";//需要转换的内容放这
s=s.replaceAll("\\n","");
s=s.replaceAll(" ","");
String[] t=s.split(";");
StringBuilder f= new StringBuilder();
for (String value : t) {
if (value.contains("R2.id.")) {
String id = value.replaceAll("@BindView\\(R2.id.", "").split("\\)")[0];
String name = value.split("\\)")[1].split(" ")[1];
String type=value.split("\\)")[1].split(" ")[0];
f.append(name).append("=("+type+")findViewById(R.id.").append(id).append(");\n");
}
}
System.out.println(f);
}
}
作者:飞翔公园
链接:http://www.javaheidong.com/blog/article/114367/c850bc66c919dd14888d/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!