MVP和sqlite数据库,XRecyclerView上啦加载下拉刷新的第三方注册登录,列表
2017-11-12 20:43
751 查看
OkHttp框架是一个用得比较广,比较频繁的一个网络请求框架,在这里就不进行过多的赘述了,因为简单的demo用到的也是比较简单的功能。
MVP是一种架构,是区别于MVC的,可以有更好的去耦合性,最终的目的都是方便于我们的开发维护工作。有兴趣的可以google了解详情,也可以通过我这个简单的demo有个初步的一些体验与了解
下面我来讲述一下具体该怎么在代码里面用。
第一:新增一个Project,使用RxAndroid之前的一些工具包的准备(在Module:app里面的build.gradle的dependencies里面添加 ),下面是我的build.gradle的代码
第二:把框架搭起来,新增四个package(bean,model,presenter,view),bean包主要是装一些java的基类,这里可用也可以不用,model包里面装一些与数据打交道的类,presenter包里面装一些model包里面的数据需要在view包里面呈现的类,view包里面就是界面更新的接口类
第三:给出指定的工作流程,使用此框架实现它,我这个代码里面的工作流程:点击界面的按钮,从网上获取图片,然后显示在界面上。
第四:根据给出的工作流,一步步代码实现
①界面的实现(一个Button,一个ImageView),以下是布局代码
②根据工作流程,界面处理的接口定义
③数据处理的逻辑实现,定义被观察者,在这里实现下载图片的异步操作(代表着简单的耗时操作)
④通过数据处理层(model)以及界面接口层(view),完成这两者的联系,实现这个A数据处理应该分发给B界面去显示
⑤完成Activity的工作流程
第五:运行此程序,体验一下这个简单demo吧
看以下代码
一、ManActivity代码:注册和登录的Fragment
public class MainActivity extends AppCompatActivity {
private RelativeLayout relativeLayout;
private RadioGroup radioGroup;
// private FragmentTransaction transaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//用fragment替换的布局
relativeLayout = (RelativeLayout) findViewById(R.id.rela);
radioGroup = (RadioGroup) findViewById(R.id.radio_group);
//进入页面先展示 注册页面
getSupportFragmentManager().beginTransaction().replace(R.id.rela,new ZhuceFragment()).commit();
// transaction = getSupportFragmentManager().beginTransaction();
//按钮选中的监听
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.btn_zhuce:
getSupportFragmentManager().beginTransaction().replace(R.id.rela,new ZhuceFragment()).commit();
break;
case R.id.btn_denglu:
getSupportFragmentManager().beginTransaction().replace(R.id.rela,new DengluFragment()).commit();
break;
}
//执行替换
// transaction.commit();
}
});
}
}
二、SecondActivity页面:页面的Fragment
public class SecondActivity extends AppCompatActivity {
private RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.rela02);
radioGroup = (RadioGroup) findViewById(R.id.radio_group);
//进入页面展示个人中心选项卡内容
getSupportFragmentManager().beginTransaction().replace(R.id.rela02,new GeRenFragment()).commit();
//按钮选中的监听
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.btn_geren:
getSupportFragmentManager().beginTransaction().replace(R.id.rela02,new GeRenFragment()).commit();
break;
case R.id.btn_liebiao:
getSupportFragmentManager().beginTransaction().replace(R.id.rela02,new LieBiaoFragment()).commit();
break;
}
//执行替换
// transaction.commit();
}
});
}
}
三、ThirdActivity页面:
public class ThirdActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
TextView textView = (TextView) findViewById(R.id.third_text);
Intent intent = getIntent();
String title = intent.getStringExtra("title");
textView.setText(title);
}
}
四、创建数据库
public class MyOpenHelper extends SQLiteOpenHelper{
public MyOpenHelper(Context context) {
super(context, "day11.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
//创建数据库
db.execSQL("create table wht(username varchar(20),password varchar(20))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
五、model:注册进数据库
public class MyModel {
//注册 访问数据库
public void zhuce(Context context, String phone, String password, ZhuceModelCallBack zhuceModelCallBack) {
//注册成功的回调
// zhuceModelCallBack.zhuce_success();
MyOpenHelper openHelper = new MyOpenHelper(context);
SQLiteDatabase database = openHelper.getReadableDatabase();
database.execSQL("insert into wht(username,password) values(?,?)",new String[]{phone,password});
database.close();
//注册成功的回调
zhuceModelCallBack.zhuce_success();
}
//登录 访问数据库
public void denglu(Context context, String phone, String password, DengluModelCallBack dengluModelCallBack) {
MyOpenHelper openHelper = new MyOpenHelper(context);
SQLiteDatabase database = openHelper.getWritableDatabase();
Cursor cursor = database.rawQuery("select * from wht where username = ? and password = ?", new String[]{phone, password});
if(cursor.moveToNext()){
//如果找到了 就 成功的回调
dengluModelCallBack.denglu_success();
}else{
//没找到就失败的回调
dengluModelCallBack.denglu_fail();
}
}
}
六、登录的Fragment
public class DengluFragment extends Fragment{
private EditText deng_phone;
private EditText deng_password;
private Button denglu;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_denglu, container, false);
deng_phone = (EditText) view.findViewById(R.id.deng_phone);
deng_password = (EditText) view.findViewById(R.id.deng_password);
denglu = (Button) view.findViewById(R.id.denglu);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final MyPresenter myPresenter = new MyPresenter(getActivity(), new MyPresenter.ZhuceViewCallBack() {
@Override
public void zhu_phone_empty() {
}
@Override
public void zhu_pass_empty() {
}
@Override
public void zhu_success() {
}
@Override
public void zhu_fail() {
}
}, new MyPresenter.LoginViewCallBack() {
@Override
public void deng_phone_empty() {
Toast.makeText(getActivity(),"登录手机号不能为空",Toast.LENGTH_SHORT).show();
}
@Override
public void deng_pass_empty() {
Toast.makeText(getActivity(),"登录密码不能为空",Toast.LENGTH_SHORT).show();
}
@Override
public void deng_success() {
Toast.makeText(getActivity(),"登录成功!即将跳转到主页面",Toast.LENGTH_SHORT).show();
//跳转到主页面
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent intent = new Intent(getActivity(), SecondActivity.class);
startActivity(intent);
}
@Override
public void deng_fail() {
Toast.makeText(getActivity(),"没找到!",Toast.LENGTH_SHORT).show();
}
});
//登录按钮的点击事件
denglu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myPresenter.Denglu_Panduan(deng_phone.getText().toString(),deng_password.getText().toString());
}
});
}
}
七、注册的Fragment
public class ZhuceFragment extends Fragment {
private EditText zhu_phone;
private EditText zhu_password;
private Button zhuce;
private MyPresenter myPresenter;
//注册页面
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//填充布局
View view = inflater.inflate(R.layout.fragment_zhuce,container,false);
zhu_phone = (EditText)
1106f
view.findViewById(R.id.zhu_phone);
zhu_password = (EditText) view.findViewById(R.id.zhu_password);
zhuce = (Button) view.findViewById(R.id.zhuce);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//new出presenter对象
myPresenter = new MyPresenter(getActivity(), new MyPresenter.ZhuceViewCallBack() {
@Override
public void zhu_phone_empty() {
Toast.makeText(getActivity(), "注册手机号不能为空", Toast.LENGTH_SHORT).show();
}
@Override
public void zhu_pass_empty() {
Toast.makeText(getActivity(),"注册密码不能为空",Toast.LENGTH_SHORT).show();
}
@Override
public void zhu_success() {
Toast.makeText(getActivity(),"注册成功!请前往登录页面!",Toast.LENGTH_SHORT).show();
}
@Override
public void zhu_fail() {
Toast.makeText(getActivity(),"不存在!",Toast.LENGTH_SHORT).show();
}
}, new MyPresenter.LoginViewCallBack() {
@Override
public void deng_phone_empty() {
}
@Override
public void deng_pass_empty() {
}
@Override
public void deng_success() {
}
@Override
public void deng_fail() {
}
});
//点击注册按钮 调用p层去逻辑判断非空
zhuce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//p层逻辑判断
myPresenter.Zhuce_Panduan(zhu_phone.getText().toString(),zhu_password.getText().toString());
}
});
}
}
八、页面个人中心的Fragment
public class GeRenFragment extends Fragment{
private static final String TAG = "MainActivity";
private static final String APP_ID = "1105602574";//官方获取的APPID
private Tencent mTencent;
private BaseUiListener mIUiListener;
private UserInfo mUserInfo;
private Button button;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_geren, container, false);
button = (Button) view.findViewById(R.id.button);
//传入参数APPID和全局Context上下文
mTencent = Tencent.createInstance(APP_ID, getActivity().getApplicationContext());
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/**通过这句代码,SDK实现了QQ的登录,这个方法有三个参数,第一个参数是context上下文,第二个参数SCOPO 是一个String类型的字符串,表示一些权限
官方文档中的说明:应用需要获得哪些API的权限,由“,”分隔。例如:SCOPE = “get_user_info,add_t”;所有权限用“all”
第三个参数,是一个事件监听器,IUiListener接口的实例,这里用的是该接口的实现类 */
mIUiListener = new BaseUiListener();
//all表示获取所有权限
mTencent.login(getActivity(),"all", mIUiListener);
}
});
}
// public void buttonLogin(View v){
// }
/**
* 自定义监听器实现IUiListener接口后,需要实现的3个方法
* onComplete完成 onError错误 onCancel取消
*/
private class BaseUiListener implements IUiListener {
@Override
public void onComplete(Object response) {
Toast.makeText(getActivity(), "授权成功", Toast.LENGTH_SHORT).show();
Log.e(TAG, "response:" + response);
JSONObject obj = (JSONObject) response;
try {
String openID = obj.getString("openid");
String accessToken = obj.getString("access_token");
String expires = obj.getString("expires_in");
mTencent.setOpenId(openID);
mTencent.setAccessToken(accessToken,expires);
QQToken qqToken = mTencent.getQQToken();
mUserInfo = new UserInfo(getActivity().getApplicationContext(),qqToken);
mUserInfo.getUserInfo(new IUiListener() {
@Override
public void onComplete(Object response) {
Log.e(TAG,"登录成功"+response.toString());
}
@Override
public void onError(UiError uiError) {
Log.e(TAG,"登录失败"+uiError.toString());
}
@Override
public void onCancel() {
Log.e(TAG,"登录取消");
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onError(UiError uiError) {
Toast.makeText(getActivity(), "授权失败", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(getActivity(), "授权取消", Toast.LENGTH_SHORT).show();
}
}
/**
* 在调用Login的Activity或者Fragment中重写onActivityResult方法
* @param requestCode
* @param resultCode
* @param data
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == Constants.REQUEST_LOGIN){
Tencent.onActivityResultData(requestCode,resultCode,data,mIUiListener);
}
super.onActivityResult(requestCode, resultCode, data);
}
}
九、列表的Fragment
public class LieBiaoFragment extends Fragment{
private SpringView springView;
private RecyclerView recyclerView;
private RecyAdapter recyAdapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_liebiao,container,false);
springView = (SpringView) view.findViewById(R.id.springview);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
return view;
}
int page = 0;
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
recyAdapter = new RecyAdapter(getActivity());
LinearLayoutManager manager = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(manager);
//进入入眠
getData();
springView.setHeader(new DefaultHeader(getActivity()));
springView.setFooter(new DefaultFooter(getActivity()));
springView.setListener(new SpringView.OnFreshListener() {
@Override
public void onRefresh() {
page ++;
getData();
springView.onFinishFreshAndLoad();
}
@Override
public void onLoadmore() {
page = 0;
getData();
springView.onFinishFreshAndLoad();
}
});
}
//
public void getData(){
final String path = "http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.billboard.billList&type=1&size=10&offset="+page;
OkhttpUtils.getInstance().asy(null, path, new AbstractUiCallBack<RecyBean>() {
@Override
//abstractUiCallBack的接口回调
public void success(RecyBean bean) {
//获取数据 .调用适配器中的添加数据的方法,,刷新添加到前面
recyAdapter.addData(bean.getSong_list());
recyclerView.setAdapter(recyAdapter);
}
@Override
public void failure(Exception e) {
Toast.makeText(getActivity(),"e:"+e,Toast.LENGTH_SHORT).show();
}
});
}
}
十、ModelCallBack和ViewCallBack
登录的ModelCallBack
public interface DengluModelCallBack {
public void denglu_success();
public void denglu_fail();
}
登陆的view
public interface LoginViewCallBack {
//登陆判断非空
public void deng_phone_empty();
public void deng_pass_empty();
public void deng_success();
public void deng_fail();
}
注册的modelcallback
public interface ZhuceModelCallBack {
public void zhuce_success();
}
注册的viewcallback
public interface ZhuceViewCallBack {
//注册判断非空
public void zhu_phone_empty();
public void zhu_pass_empty();
public void zhu_success();
public void zhu_fail();
}
十一、presenset
public class MyPresenter {
FragmentActivity activity;
ZhuceViewCallBack zhuceViewCallback;
LoginViewCallBack loginViewCallBack;
public MyPresenter(FragmentActivity activity,ZhuceViewCallBack zhuceViewCallback,LoginViewCallBack loginViewCallBack){
this.activity = activity;
this.zhuceViewCallback = zhuceViewCallback;
this.loginViewCallBack = loginViewCallBack;
}
//new出model对象
MyModel myModel = new MyModel();
public interface ZhuceViewCallBack {
//注册判断非空
public void zhu_phone_empty();
public void zhu_pass_empty();
public void zhu_success();
public void zhu_fail();
}
public interface LoginViewCallBack {
//登陆判断非空
public void deng_phone_empty();
public void deng_pass_empty();
public void deng_success();
public void deng_fail();
}
//p层里面的逻辑判断 非空
public void Zhuce_Panduan(String phone, String password) {
if(TextUtils.isEmpty(phone)){
//接口回调
zhuceViewCallback.zhu_phone_empty();
return;
}
if(TextUtils.isEmpty(password)){
//接口回调
zhuceViewCallback.zhu_pass_empty();
return;
}
myModel.zhuce(activity,phone,password, new ZhuceModelCallBack() {
@Override
public void zhuce_success() {
zhuceViewCallback.zhu_success();
}
});
}
//p层里面的逻辑判断 非空
public void Denglu_Panduan(String phone, String password) {
if(TextUtils.isEmpty(phone)){
//接口回调
loginViewCallBack.deng_phone_empty();
return;
}
if(TextUtils.isEmpty(password)){
//接口回调
loginViewCallBack.deng_pass_empty();
return;
}
myModel.denglu(activity,phone,password, new DengluModelCallBack() {
@Override
public void denglu_success() {
loginViewCallBack.deng_success();
}
@Override
public void denglu_fail() {
loginViewCallBack.deng_fail();
}
});
}
}
十二、RecyAdapter列表适配器
public class RecyAdapter extends RecyclerView.Adapter<RecyAdapter.myViewHolder>{
List<RecyBean.SongListBean> listda;
Context context;
public RecyAdapter(Context context) {
this.context = context;
}
public void addData(List<RecyBean.SongListBean> SongList) {
if(listda == null){
//创建listda
listda = new ArrayList<>();
}
listda.addAll(SongList);
notifyDataSetChanged();
}
@Override
public myViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View.inflate(context, R.layout.recy_item,null);
myViewHolder myViewHolder = new myViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(myViewHolder holder, final int position) {
String[] split = listda.get(position).getPic_big().split("@");
ImageLoader.getInstance().displayImage(split[0],holder.imageView);
holder.textViewe.setText(listda.get(position).getTitle());
//点击事件
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, ThirdActivity.class);
intent.putExtra("title",listda.get(position).getTitle());
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return listda == null?0:listda.size();
}
static class myViewHolder extends RecyclerView.ViewHolder{
private final ImageView imageView;
private final TextView textViewe;
public myViewHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.image);
textViewe = (TextView) itemView.findViewById(R.id.text);
}
}
}
十三、imageloader
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build();
ImageLoader.getInstance().init(configuration);
}
}
布局mainactivity布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!--将被替换的布局-->
<RelativeLayout
android:id="@+id/rela"
android:layout_weight="6"
android:layout_width="match_parent"
android:layout_height="0dp">
</RelativeLayout>
<RadioGroup
android:id="@+id/radio_group"
android:background="#fddfdd"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:checked="true"
android:id="@+id/btn_zhuce"
android:gravity="center"
android:padding="20dp"
android:textSize="23sp"
android:button="@null"
android:text="注册"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/btn_denglu"
android:gravity="center"
android:padding="20dp"
android:textSize="23sp"
android:button="@null"
android:text="登录"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</RadioGroup>
</LinearLayout>
secondactivity布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:background="#3453"
android:padding="20dp"
android:textSize="23sp"
android:gravity="center_horizontal"
android:text="首页"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/rela02"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6">
</RelativeLayout>
<RadioGroup
android:id="@+id/radio_group"
android:background="#3453"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
<RadioButton
android:checked="true"
android:id="@+id/btn_geren"
android:gravity="center"
android:padding="20dp"
android:textSize="23sp"
android:button="@null"
android:text="个人中心"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/btn_liebiao"
android:gravity="center"
android:padding="20dp"
android:textSize="23sp"
android:button="@null"
android:text="列表"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</RadioGroup>
</LinearLayout>
thirdactivity布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context="com.example.a171111_zhoukao2_moni.ThirdActivity">
<TextView
android:background="#ff0"
android:id="@+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
dengluFragment布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="match_parent">
<EditText
android:hint="请输入手机号"
android:layout_marginTop="200dp"
android:id="@+id/deng_phone"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<EditText
android:hint="请输入密码"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/deng_password"
/>
<Button
android:padding="10dp"
android:textSize="23sp"
android:layout_marginTop="50dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/denglu"
android:text="登录"
/>
</LinearLayout>
zhuceFragment布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="match_parent">
<EditText
android:hint="请输入手机号"
android:layout_marginTop="200dp"
android:id="@+id/zhu_phone"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<EditText
android:hint="请输入密码"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/zhu_password"
/>
<Button
android:padding="10dp"
android:textSize="23sp"
android:layout_marginTop="50dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/zhuce"
android:text="注册"
/>
</LinearLayout>
gerenzhongxinFragment布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击QQ登录"
android:onClick="buttonLogin"
android:layout_centerInParent="true"
android:textSize="16sp"
android:textColor="#f4736e"/>
</LinearLayout>
liebiaoFragment页面
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<com.liaoinstan.springview.widget.SpringView
android:layout_width="match_parent"
android:id="@+id/springview"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerview" >
</android.support.v7.widget.RecyclerView>
</com.liaoinstan.springview.widget.SpringView>
</LinearLayout>
recy_item适配器的结果布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="10dp"
android:gravity="center_vertical"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:src="@mipmap/ic_launcher"
android:layout_width="120dp"
android:layout_height="120dp" />
<TextView
android:text="a"
android:id="@+id/text"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
-------------------------------------------------------------------------------------------导依赖
bean类自己根据链接获取的数据写
OKhttp是导一个OKhttp的文件夹
springview的依赖
compile 'com.liaoinstan.springview:library:1.2.6'
recyclerview的依赖
compile 'com.github.liuguangqiang.SuperRecyclerView:super-recyclerview:0.1.2'
imageloader的依赖
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
okhttp的依赖
compile 'com.squareup.okhttp3:okhttp:3.9.0'
gson的依赖
compile 'com.google.code.gson:gson:2.8.2'
相关文章推荐
- 使用MVP注册登录模块+封装的OKhttp,拦截器+QQ第三方登录+RecyclerView+SpringView上拉加载下拉刷新网络数据
- 登录注册,第三方登录,recyclerView列表上拉加载,下拉刷新
- MVP登录+recyclerview列表展示(带刷新效果)
- MVP实现Recyclerview加Springview上拉加载下拉刷新点击条目可跳转到购物车
- RecyclerView和SwipeRefreshLayout结合实现列表的上拉加载下拉刷新
- MVP+XRecyclerView+okhttp+glide,列表或者网格显示所加载的数据
- 用Recyclerview实现列表分组、下拉刷新以及上拉加载更多
- 解决RecyclerView上拉加载、下拉刷新、Header和Footer的第三方解决方案
- mvp下RecyclerView下拉刷新上拉加载Demo
- 用RecyclerView实现新闻列表页,包括头部的图片轮播,两种Item显示方式,下拉刷新和上拉加载以及限制列表的加载条目数
- RecyclerView下拉刷新、上拉加载更多以及复杂列表布局的实现
- MVP模式 + RecyclerView瀑布流 + 上拉加载、下拉刷新
- 解决RecyclerView上拉加载、下拉刷新、Header和Footer的第三方解决方案
- 用Recyclerview实现列表分组、下拉刷新以及上拉加载--源码
- mvp+retrofit+rxjava xrecyclerview实现多条目 下拉刷新 下拉加载 点击跳转
- Mvp+OkHttp+XRecyclerView------上拉加载下拉刷新
- RecyclerView 上拉加载更多以及下拉刷新
- 【Android】给RecyclerView添加下拉刷新和加载更多(二)
- RecyclerView 添加下拉刷新和上拉加载更多
- RecyclerView实例-实现可下拉刷新上拉加载更多并可切换线性流和瀑布流模式(1)