The use of xUtils3.0 (1) IOC

First of all, nothing to say, put the github address of xUtils:
https://github.com/wyouflf/xUtils3


The author's original words: xUtils3 api has changed a lot;
xUtils 2.x is not very compatible with Android 6.0, please as soon as possible Upgrade to xUtils3;
xUtils is at least compatible with Android 4.0 (api level 14); ( please remember to pay attention to the minsdk of your own project, an error will be reported when running below 14 ) The
database api is simplified to improve performance and achieve the same performance as greenDao.
 … ...


This article briefly talks about the usage of IOC

1. Configure the
required :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

initialization:
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG);
        //Whether to output the debug log, turning on the debug will affect the performance. (This line of code may or may not be required)
    }
}


After writing MyApplicaton, specify the application through the android:name attribute in AndroidManifest.xml:

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 </application>


2. Start using
@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
    @ViewInject(R.id.fab)
    private FloatingActionButton button;
    //Note here that variables and methods must be private
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        x.view().inject(this);
        //Similar to the function of enabling xUtils injection
    }
    @Event(R.id.fab) //Parameter support array value={id1, id2, id3}
    private void clickMe(View view){
        Snackbar.make(view,"ioc succeed!",Snackbar.LENGTH_SHORT).show();
    }
}


Overall, the usage is similar to ButterKnife.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326636695&siteId=291194637