a: initialization
Create a class to inherit Application
public class MyApplication extends Application{ @Override public void onCreate() { super.onCreate(); x.Ext.init(this); } }b: Annotation controls are the same as before
@ViewInject (R.id.buton) private Button button;
c: click event
@Event(value = R.id.buton) private void onclick(View view) { Toast.makeText(this, "I was clicked", Toast.LENGTH_SHORT).show(); httpUtilsPost(); }
d:post request
<pre name="code" class="java"> private void httpUtilsPost() { RequestParams params = new RequestParams(url); params.addBodyParameter("key", "value"); x.http().post(params, new Callback.CacheCallback<String>() { @Override public boolean onCache(String s) { return false; } @Override public void onSuccess(String result) { textView.setText(result ); } @Override public void onError(Throwable throwable, boolean b) { Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show(); } @Override public void onCancelled (CancelledException e) { Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show(); } @Override public void onFinished() { } }); }
e: Finally, don't forget this sentence x.view().inject(this);
For more details, please see the author's documentation https://github.com/wyouflf/xUtils3