資源簡介
傳統的rxjava和retrofit結合的使用方法

代碼片段和文件信息
package?com.example.retrofit.activity;
import?android.app.ProgressDialog;
import?android.os.Bundle;
import?android.view.View;
import?android.widget.TextView;
import?com.example.retrofit.R;
import?com.example.retrofit.http.HttpService;
import?com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import?java.util.concurrent.TimeUnit;
import?okhttp3.OkHttpClient;
import?retrofit2.Retrofit;
import?retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import?retrofit2.converter.gson.GsonConverterFactory;
import?rx.Observable;
import?rx.Subscriber;
import?rx.android.schedulers.AndroidSchedulers;
import?rx.schedulers.Schedulers;
public?class?MainActivity?extends?RxAppCompatActivity?implements?View.onclickListener?{
????private?TextView?tvMsg;
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????tvMsg?=?(TextView)?findViewById(R.id.tv_msg);
????????findViewById(R.id.btn_simple).setonclickListener(this);
????}
????@Override
????public?void?onclick(View?v)?{
????????switch?(v.getId())?{
????????????case?R.id.btn_simple:
????????????????onButton9Click();
????????????????break;
????????}
????}
????/**
?????*?Retrofit加入rxjava實現http請求
?????*/
????private?void?onButton9Click()?{
????????//手動創建一個OkHttpClient并設置超時時間
????????okhttp3.OkHttpClient.Builder?builder?=?new?OkHttpClient.Builder();
????????builder.connectTimeout(5?TimeUnit.SECONDS);
????????Retrofit?retrofit?=?new?Retrofit.Builder()
????????????????.client(builder.build())
????????????????.addConverterFactory(GsonConverterFactory.create())
????????????????.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
????????????????.baseUrl(“http://www.izaodao.com/Api/“)
????????????????.build();
//????????加載框
????????final?ProgressDialog?pd?=?new?ProgressDialog(this);
????????HttpService?apiService?=?retrofit.create(HttpService.class);
????????Observable?observable?=?apiService.getAllVedioBy(true);
????????observable.subscribeOn(Schedulers.io()).unsubscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
????????????????.subscribe(
????????????????????????new?Subscriber()?{
????????????????????????????@Override
????????????????????????????public?void?onCompleted()?{
????????????????????????????????if?(pd?!=?null?&&?pd.isShowing())?{
????????????????????????????????????pd.dismiss();
????????????????????????????????}
????????????????????????????}
????????????????????????????@Override
????????????????????????????public?void?onerror(Throwable?e)?{
????????????????????????????????if?(pd?!=?null?&&?pd.isShowing())?{
????????????????????????????????????pd.dismiss();
????????????????????????????????}
????????????????????????????}
????????????????????????????@Override
????????????????????????????public?void?onNext(RetrofitEntity?retrofitEntity)?{
???????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????105??2016-10-20?10:56??RxjavaRetrofitDemo-master\.gitignore
?????文件??????????8??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\.gitignore
?????文件??????13165??2016-10-24?09:09??RxjavaRetrofitDemo-master\app\app.iml
?????文件???????1441??2016-10-21?14:18??RxjavaRetrofitDemo-master\app\build.gradle
?????文件????????706??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\proguard-rules.pro
?????文件???????1034??2016-10-24?09:10??RxjavaRetrofitDemo-master\app\src\main\AndroidManifest.xm
?????文件???????3452??2016-10-24?09:17??RxjavaRetrofitDemo-master\app\src\main\java\com\example\retrofit\activity\MainActivity.java
?????文件????????668??2016-10-24?09:14??RxjavaRetrofitDemo-master\app\src\main\java\com\example\retrofit\activity\RetrofitEntity.java
?????文件????????722??2016-10-24?09:13??RxjavaRetrofitDemo-master\app\src\main\java\com\example\retrofit\activity\Subject.java
?????文件????????558??2016-10-24?09:17??RxjavaRetrofitDemo-master\app\src\main\java\com\example\retrofit\http\HttpService.java
?????文件????????898??2016-10-21?13:24??RxjavaRetrofitDemo-master\app\src\main\res\layout\activity_down_laod.xm
?????文件????????692??2016-10-24?09:11??RxjavaRetrofitDemo-master\app\src\main\res\layout\activity_main.xm
?????文件???????1414??2016-10-21?13:44??RxjavaRetrofitDemo-master\app\src\main\res\layout\view_item_holder.xm
?????文件???????3418??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\mipmap-hdpi\ic_launcher.png
?????文件???????2206??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\mipmap-mdpi\ic_launcher.png
?????文件???????4842??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\mipmap-xhdpi\ic_launcher.png
?????文件???????7718??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\mipmap-xxhdpi\ic_launcher.png
?????文件??????10486??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png
?????文件????????214??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\values\colors.xm
?????文件????????216??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\values\dimens.xm
?????文件?????????84??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\values\strings.xm
?????文件????????394??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\values\st
?????文件????????364??2016-10-20?10:56??RxjavaRetrofitDemo-master\app\src\main\res\values-w820dp\dimens.xm
?????文件????????574??2016-10-20?10:56??RxjavaRetrofitDemo-master\build.gradle
?????文件??????53636??2016-10-20?10:56??RxjavaRetrofitDemo-master\gradle\wrapper\gradle-wrapper.jar
?????文件????????237??2016-10-20?10:56??RxjavaRetrofitDemo-master\gradle\wrapper\gradle-wrapper.properties
?????文件????????872??2016-10-20?10:56??RxjavaRetrofitDemo-master\gradle.properties
?????文件???????5131??2016-10-20?10:56??RxjavaRetrofitDemo-master\gradlew
?????文件???????2404??2016-10-20?10:56??RxjavaRetrofitDemo-master\gradlew.bat
?????文件???????1097??2016-10-20?10:56??RxjavaRetrofitDemo-master\LICENSE
............此處省略26個文件信息
評論
共有 條評論