• 大小: 97KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 其他
  • 标签: Retrofit  

资源简介

Retrofit的简单使用例子

资源截图

代码片段和文件信息

package com.rickge.learnretrofit;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.rickge.learnretrofit.HttpService.RetrofitUtil;
import com.rickge.learnretrofit.HttpService.TweetService;
import com.rickge.learnretrofit.bean.PageBean;
import com.rickge.learnretrofit.bean.ResultBean;
import com.rickge.learnretrofit.bean.Tweet;
import com.rickge.learnretrofit.bean.TweetLike;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity implements View.onclickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initWidget();

    }

    private void initWidget() {
        Button download = (Button) findViewById(R.id.bt_download);
        download.setonclickListener(this);
    }


    @Override
    public void onclick(View v) {
        switch (v.getId()){
            case R.id.bt_download:
                getTweetLikeSync();

                getTweetLikeAsync();
                break;
        }
    }

    private void getTweetLikeSync() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                TweetService tweetService = RetrofitUtil.getRetrofit().create(TweetService.class);
                Call>> callTweetLike = tweetService.listTweetLike(“13a6c06c40a866bb80e8373a6fceb9f6.json“);
                Call>> callTweet = tweetService.listTweet(“52e5798640f46ff2803867f5199c92cf.json“);

                try {
                    Response>> responseTweetLike = callTweetLike.execute();
                    ResultBean> resultBeanTweetLike = responseTweetLike.body();
                    Log.i(“MainActivity Sync“ resultBeanTweetLike.toString());

                    Response>> responseTweet = callTweet.execute();
                    ResultBean> resultBeanTweet = responseTweet.body();
                    Log.i(“MainActivity Sync“ resultBeanTweet.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private void getTweetLikeAsync() {
        TweetService tweetService = RetrofitUtil.getRetrofit().create(TweetService.class);
        Call>> callTweetLike = tweetService.listTweetLike(“13a6c06c40a866bb80e8373a6fceb9f6.json“);
        Call>> callTweet = tweetService.listTweet(“52e5798640f46ff2803867f5199c92cf.json“);

        callTweetLike.enqueue(new Callback>>()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-02-08 15:11  LearnRetrofit\
     文件         127  2017-02-08 12:02  LearnRetrofit\.gitignore
     文件         867  2017-02-08 12:08  LearnRetrofit\LearnRetrofit.iml
     目录           0  2017-02-08 15:11  LearnRetrofit\app\
     文件           8  2017-02-08 12:02  LearnRetrofit\app\.gitignore
     文件       11480  2017-02-08 13:13  LearnRetrofit\app\app.iml
     文件         809  2017-02-08 12:15  LearnRetrofit\app\build.gradle
     目录           0  2017-02-08 15:11  LearnRetrofit\app\libs\
     文件         662  2017-02-08 12:02  LearnRetrofit\app\proguard-rules.pro
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\androidTest\
     目录           0  2017-02-08 15:11  LearnRetrofit\app\src\androidTest\java\
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\
     文件         750  2017-02-08 13:14  LearnRetrofit\app\src\main\AndroidManifest.xml
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\java\
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\java\com\
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\java\com\rickge\
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\HttpService\
     文件         980  2017-02-08 12:49  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\HttpService\RetrofitUtil.java
     文件         662  2017-02-08 13:52  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\HttpService\TweetService.java
     文件        4035  2017-02-08 14:59  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\MainActivity.java
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\bean\
     文件         172  2017-02-08 13:47  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\bean\Author.java
     文件         347  2017-02-08 13:47  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\bean\PageBean.java
     文件         226  2017-02-08 12:25  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\bean\ResultBean.java
     文件         350  2017-02-08 13:48  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\bean\Tweet.java
     文件         230  2017-02-08 13:48  LearnRetrofit\app\src\main\java\com\rickge\learnretrofit\bean\TweetLike.java
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\res\
     目录           0  2017-02-08 15:11  LearnRetrofit\app\src\main\res\drawable\
     目录           0  2017-02-08 15:10  LearnRetrofit\app\src\main\res\layout\
............此处省略30个文件信息

评论

共有 条评论