SmartFindViewById

Compatible with: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio
Oct 11, 2017
1 209
This plugin is used for generating findViewById & onClick code automatically in Android develop.
As you need to findViewById, you must provide a target Android layout file name, then this plugin will attempt to find the Android layout file in the following ways by order smartly:
  1. User select the layout file name for himself, e.g., user select the activity_main in code setContentView(R.layout.activity_main)
  2. the line where the caret positioning
  3. If the current class file is an Activity subclass, the setContentView(R.layout.) will be checked
  4. If the current class file is an Fragment subclass, the inflate(R.layout.) will be checked
  5. If the current class file is an RecyclerView.Adapter subclass, the inflate(R.layout.) will be checked
  6. popup an edit dialog to ask user to input the layout file name
Once the layout file is found, this plugin will show a dialog to display the detail of the view in the layout file name and it can ignore(uncheck) the findViewById code already exist. You can also check or uncheck to decide which view code to generate.
Besides, this plugin support to detect the include layout file and use a rootView to findViewById.
(该插件可以依次通过
  1. 选中布局文件名,如选中代码段 setContentView(R.layout.activity_main) 中的 activity_main
  2. 检测当前光标所在行是否包含布局文件名(通过 R.layout. 前缀判断)
  3. Activity setContentView(R.layout.xxx) 方法布局文件参数
  4. Fragment(包括 support_v4 fragment) 中 onCreateView 方法中 inflate(R.layout.xxx... 布局参数
  5. RecyclerViewAdapter 中 onCreateViewHolder 方法中 inflate(R.layout.xxx... 布局参数
  6. 弹输入框提示手动输入
来逐一尝试获取目标布局文件名,优先级从高到低,一旦有一个方法获取到了有效的布局文件名, 就会展示对应布局文件的所有拥有 id 的 View 控件,然后可以选择生成对应的 findViewById 和 onClick 点击事件代码。
目前还支持展示和生成 include 布局下的 View 控件和支持 rootView.findViewById.

Download plugin

Recent change notes

  • Fix a bug when adding new switch statement to existed onClick method.
  • Add TODO comment in onClick method; Make Android RadioButton do not generate onClick by default.
  • Generate the findViewById code near the opened editor's caret.