android 第三方库使用笔记

android 第三方库使用笔记

retrofit android网络请求库

private void getInfo() {
        RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(
                "https://api.github.com").build();

        GitHubService service = restAdapter.create(GitHubService.class);

        service.listRepos("octocat", new Callback>() {

            @Override
            public void failure(RetrofitError arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void success(List list, Response arg1) {
                for (Repos repos2 : list) {
                    System.out.println(repos2.full_name);
                }

            }
        });

    }

    public interface GitHubService {
        @GET("/users/{user}/repos")
        void listRepos(@Path("user") String user, Callback> cb);

    }

RxAndroid

打印hello world

 Observable myObservable = Observable.create(
                new Observable.OnSubscribe() {
                    @Override
                    public void call(Subscribersuper String> sub) {
                        sub.onNext("Hello, world!");
                        sub.onCompleted();
                    }
                }
        );

        Subscriber mySubscriber = new Subscriber() {
            @Override
            public void onNext(String s) { tv.setText(s); }

            @Override
            public void onCompleted() { }

            @Override
            public void onError(Throwable e) { }
        };


        myObservable.subscribe(mySubscriber);

绑定点击事件

  ViewObservable.clicks(tv).subscribe(new Action1() {
            @Override
            public void call(OnClickEvent onClickEvent) {
                Toast.makeText(getApplicationContext(),"fdfdf",Toast.LENGTH_LONG).show();;
            }
        });

绑定activity

Observable myObservable = Observable.create(
                new Observable.OnSubscribe() {
                    @Override
                    public void call(Subscriber sub) {
                        sub.onNext("Hello, world!");
                        sub.onCompleted();
                    }
                }
        );
        AppObservable.bindActivity(this, myObservable).subscribe(new Action1() {
            @Override
            public void call(String s) {
                 tv.setText(s);
            }
        });

你可能感兴趣的:(第三方库使用,网络,库,android)