Giter Club home page Giter Club logo

findview's Introduction

FindView

Auto create view instance in activity and fragment, with the annotation @FindView.

ViewNamingRule

First of all, you must comply with the ViewNamingRule.

layout

The layout file name of XxxActivity must be activity_xxx.xml. Likewise, XxxXxxxActivity -> activity_xxx_xxxx.xml, XxxFragment -> fragment_xxx.xml.

view

View ids in layout must comply with the ViewNamingRule equally.

abbrev

You need to create a xml file(view_naming_rule.xml) in directory assets. Some content of this file:

<containers>
	<container name="Activity" />
	<container name="Fragment" />
</containers>
<views>
	<view name="TextView" abbrev="tv" />
	<view name="Button" abbrev="btn" />
	<view name="EditText" abbrev="edt" />
 </views>

Well, view id in layout must be named in format abbrev_pagename_logicname.

e.g.

There is a Button(text:'login') in LoginActivity, its id in layout should be 'btn_login_login', and its variable name should be loginButton. A TextView(used for showing username) in MainActivity, its id in layout should be 'tv_main_username', and its variable name should be usernameTextView. More examples in the demo.

@FindView

The annotaion that annotates view fields in an activity or a fragment.

e.g.

public class MainActivity extends BaseActivity {  
    @FindView  
    private TextView textView;  
}  

With the annotation @FindView, you don't need to use findViewById at all.

Note

To use @FindView correctly, you should use the annotation @SetLayout first.

@SetLayout

The annotaion that annotates activities and fragments.

e.g.

@SetLayout
public abstract class BaseActivity extends AppCompatActivity {
}

With the annotaton @SetLayout, you don't need to use setContentView at all. And, if you annotate @SetLayout to an activity(e.g. BaseActivity), all the activity that extends BaseActivity would be annotated by @SetLayout automatically. Also, if you don't want some activities to be annotated automatically, you can do it this way:

@SetLayout(false)
public class SomeActivity extends BaseActivity {
}

Initialization

You should initialize ViewNamingRule in method onCreate() in your Application(extends android.app.Application).

e.g.

public class MyApplication extends Application{
    @Override
    public void onCreate() {
        super.onCreate();
        ViewNamingRuleInit.getInstance().loadViewNamingRule(this);
    }
}

LICENSE

MIT LICENSE.




Email: [email protected]

findview's People

Contributors

nevaryyy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.