Android xUtils的使用

导入依赖:

implementation 'org.xutils:xutils:3.3.36'

网络权限:

自定义一个myapplication类继承自Application:

package com.example.day1xutils;

import android.app.Application;

import org.xutils.x;

public class myapplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        x.Ext.init(this);
    }
}

清单文件:

Android xUtils的使用_第1张图片

主类:

package com.example.day1xutils;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;


import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;


public class MainActivity extends AppCompatActivity {

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

        String url = "http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=20&page=1";
        RequestParams requestParams = new RequestParams(url);
        x.http().get(requestParams, new Callback.CommonCallback() {

            //成功
            @Override
            public void onSuccess(String result) {
                Log.e("onSuccess", result);

            }

            //失败
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Log.e("onError", "失败");
            }

            //调用  的回调
            @Override
            public void onCancelled(CancelledException cex) {

            }

            //不管成功还是失败都走
            @Override
            public void onFinished() {
                Log.e("onFinished", "走一遭");
            }
        });
    }

   
}

 

你可能感兴趣的:(Android xUtils的使用)