<自定义两个接口:一个总接口,一个继承它>
第一个接口:
第二个接口:
使用Xutils控件:
配置的权限:
android:name=”.application.MvpApplication”
在新建一个类
public class MvpApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
x.Ext.init(this);
x.Ext.setDebug(BuildConfig.DEBUG);
}
}
//—————————————(HttpUtils类)———
package baway.com.cj.mvptest1503a.model.utils;
import com.google.gson.Gson;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;
import java.util.HashMap;
import java.util.Iterator;
/**
* Created by cj on 2017/5/10.
*/
public class HttpUtils {
public static <T>void getTestData(String url,HashMap<String,String> hashMap, final CallbackVideoData callbackVideoData, final Class<T> clazz) {
RequestParams requestParams = new RequestParams();
requestParams.setUri(url);
if (hashMap != null) {
Iterator<String> iterator = hashMap.keySet().iterator();
while (iterator.hasNext()){
String key = iterator.next();
String value = hashMap.get(key);
requestParams.addQueryStringParameter(key, value);
}
}
// requestParams.addQueryStringParameter("token","1234");
x.http().get(requestParams, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
Gson gson = new Gson();
T t = gson.fromJson(result,clazz);
callbackVideoData.callback(t);
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
}
@Override
public void onCancelled(CancelledException cex) {
}
@Override
public void onFinished() {
}
});
}
public interface CallbackVideoData<T>{
void callback(T t);
}
}
//———————————-(BasePresenter类)
package baway.com.cj.mvptest1503a.presenter;
import baway.com.cj.mvptest1503a.view.iview.IMvpView;
/**
* Created by cj on 2017/5/9.
*/
public class BasePresenter {
private T mt;
public void attachView(T t) {
this.mt = t;
}
public T getMvpView() {
return mt;
}
}
//————————————————HomePresenter类
package baway.com.cj.mvptest1503a.presenter;
import android.util.Log;
import android.widget.ImageView;
import org.xutils.x;
import java.util.HashMap;
import baway.com.cj.mvptest1503a.model.utils.HttpUtils;
import baway.com.cj.mvptest1503a.view.iview.IHomeView;
/**
* Created by cj on 2017/5/9.
*/
public class HomePresenter extends BasePresenter {
private String url = “http://api.expoon.com/AppNews/getNewsList/type/2/p/1“;
private HashMap