Code Monkey home page Code Monkey logo

simplebutterknife's Introduction

SimpleButterKnife 是参考于框架butterknife手写的,主要实现了Android View初始化与点击事件绑定,使用相对简单些。

一、在Application中的初始化


public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // 初始化
        XBinding.init(this);
    }
}

二、在Activity添加布局注解@Builder,其他与butterknife的使用是一样的

//xml布局注解
@Builder(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
    //view初始化绑定
    @BindView(R.id.tv_hello)
    TextView mTvHello;
    @BindView(R.id.tv_butter_knife)
    TextView mTvButterKnife;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mTvHello.setText("hello x-binding");//222000


    }

    //点击事件绑定
    @OnClick({R.id.btn_show_hello,R.id.btn_show_butter_knife,R.id.btn_goto_user})
    public void onViewClick(View view) {
        switch (view.getId()){
            case R.id.btn_show_hello:
                String hello = mTvHello.getText().toString();
                Toast.makeText(this, hello, Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_show_butter_knife:
                String butterKnife = mTvButterKnife.getText().toString();
                Toast.makeText(this, butterKnife, Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_goto_user:
                startActivity(new Intent(this,UserActivity.class));
                break;
        }

    }
}

simplebutterknife's People

Contributors

751496032 avatar

Watchers

 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.