- Naming Convention
- Code Folding
- [Handling Clicks](#Handling Clicks)
| Component | Class Name | Layout Name |
|---|---|---|
| Activity | UserProfileScreenActivity | user_profile_screen_activity.xml |
| Fragment | SignUpScreenFragment | sign_up_screen_fragment.xml |
| Dialog | ChangePasswordScreenConfirmationDialog | change_password_screen_confirmation_dialog.xml |
| DialogFragment | PaymentScreenApplyCouponCodeDialogFragment | payment_screen_apply_coupon_code_dialog_fragment.xml |
| AdapterView Item | - | profile_screen_item_person.xml |
| Component | Prefix | Example @id | Java Variable |
|---|---|---|---|
| Button | btn_ | btn_login | btnLogin |
| TextView | tv_ | tv_email | tvEmail |
| ProgressBar | pb_ | pb_loading_countries | pbLoadingCountries |
TODO: Add below examples to the above table.
-
Frame Layout: fl
-
Linear Layout: ll
-
Table Layout: tl
-
Table Row: tr
-
Grid Layout: gl
-
Relative Layout: rl
-
Text View: tv
-
Button: bt
-
Check Box: cb
-
Switch: sw
-
Toggle Button: tb
-
Image Button: ib
-
Image View: iv
-
Progress Bar: pb
-
Seek Bar: sb
-
Rating Bar: rb
-
Spinner: sp
-
WebView: wv
-
Edit Text: et
-
Radio Group: rg
-
List View: lv
-
Grid View: gv
-
Expandable List View: el
-
Scroll View: sv
-
Horizontal Scroll View: hs
-
Search View:* se
-
Tab Host: th
-
Video View: vv
-
Dialer Filter: df
-
Include: ic
-
Fragment: fr
-
Custom View (other): cv
Use regions in Java classes to support code folding.
class Person {
// region Declarations
// endregion Declarations
// region Constructors
// endregion Constructors
// region Getter Setter
// endregion Getter Setter
// region Parceable
// endregion Parceable
// region Class Methods
// endregion Class Methods
// region Instance Methods
// endregion Instance Methods
}class SettingsActivity extends AppCompatActivity {
// region Declarations
// endregion Declarations
// region onCreate
// endregion onCreate
// region Overrides
// endregion Overrides
// region onClick Functions
// endregion onClick Functions
}// Bad
@Override
protected void onCreate(Bundle savedInstanceState) {
llLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
promptForLogout(SettingsActivity.this);
}
});
}
// Good
<LinearLayout
android:id="@+id/ll_logout"
android:onClick="logoutButtonClicked">
</LinearLayout>
public void logoutButtonClicked(View view) {
promptForLogout(SettingsActivity.this);
}