Add 'm' prefix to variable name. For example, 'mEdittextUserName'
Add typecasting for view. For example, '(TextView) findViewById(R.id.tv_name);'
Android View Binding (AVB) Code Generator
What is this?
Mother of this tool is a question, why should I write whole binding code in java activity when view IDs are already mentioned in XML file.
This is a tool for those android developers who don't want to waste time in writing binding code. :)
How to use
Add ids to all XML views which are required in java code
Copy XML layout file
Paste the copied file text in "XML layout" area
Now copy the generated code
Paste that code to java activity / fragment / viewholde / ... accordingly
Done!
Use in Activity
Make sure that output mode is set to Acitivities
After pasting generated code (How to use step 5), call bindViews() function after setContentView() in onCreate() method.
Use in Fragment / Viewholder etc..
Make sure that output mode is set to Fragments / ViewHolders / Others
After pasting generated code (How to use step 5), call bindViews() function when layout is populated.
Fragments: in function onViewCreated().
Viewholders: after super(view); call in constructor.
Use with ButterKnife
Butter Knife is a great and well known android library used for view injection.It is maintained by Jake Wharton. To integrate ButterKnife, check github guide.
Set output mode to ButterKnife
After pasting generated code (How to use step 5), call ButterKnife bind code when layout is populated. Make sure you are using ButterKnife library version >8.