登录注册

来源:互联网 发布:sql select 默认值 编辑:程序博客网 时间:2024/04/29 07:38

  activity_main布局

<?xml version="1.0" encoding="utf-8"?><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>


Activity类

package com.example.a171111_zhoukao2_moni;import android.support.v4.app.FragmentTransaction;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.RadioGroup;import android.widget.RelativeLayout;import com.example.a171111_zhoukao2_moni.fragment.DengluFragment;import com.example.a171111_zhoukao2_moni.fragment.ZhuceFragment;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();            }        });    }}

4个fragment

登录的

<?xml version="1.0" encoding="utf-8"?><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>


登录fragment

package com.example.a171111_zhoukao2_moni.fragment;import android.content.Intent;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.example.a171111_zhoukao2_moni.R;import com.example.a171111_zhoukao2_moni.SecondActivity;import com.example.a171111_zhoukao2_moni.jiekou.LoginViewCallBack;import com.example.a171111_zhoukao2_moni.presenter.MyPresenter;/** * Created by Menglucywhh on 2017/11/11. */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());            }        });    }}



注册的


<?xml version="1.0" encoding="utf-8"?><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>

注册Fragment


package com.example.a171111_zhoukao2_moni.fragment;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.example.a171111_zhoukao2_moni.R;import com.example.a171111_zhoukao2_moni.jiekou.ZhuceViewCallBack;import com.example.a171111_zhoukao2_moni.presenter.MyPresenter;/** * Created by Menglucywhh on 2017/11/11. */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) 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());            }        });    }}



列表的

<?xml version="1.0" encoding="utf-8"?><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>


列表Fragment

package com.example.a171111_zhoukao2_moni.fragment;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Toast;import com.example.a171111_zhoukao2_moni.R;import com.example.a171111_zhoukao2_moni.adapter.RecyAdapter;import com.example.a171111_zhoukao2_moni.bean.RecyBean;import com.example.a171111_zhoukao2_moni.okhttp.AbstractUiCallBack;import com.example.a171111_zhoukao2_moni.okhttp.OkhttpUtils;import com.liaoinstan.springview.container.DefaultFooter;import com.liaoinstan.springview.container.DefaultHeader;import com.liaoinstan.springview.widget.SpringView;/** * Created by Menglucywhh on 2017/11/11. */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();            }        });    }}



geren

<?xml version="1.0" encoding="utf-8"?><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>

GerenFramgent

package com.example.a171111_zhoukao2_moni.fragment;import android.content.Intent;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.view.animation.Animation;import android.widget.Button;import android.widget.Toast;import com.example.a171111_zhoukao2_moni.R;import com.tencent.connect.UserInfo;import com.tencent.connect.auth.QQToken;import com.tencent.connect.common.Constants;import com.tencent.tauth.IUiListener;import com.tencent.tauth.Tencent;import com.tencent.tauth.UiError;import org.json.JSONObject;/** * Created by Menglucywhh on 2017/11/11. */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);    }}

接口

DengluModelCallBack

package com.example.a171111_zhoukao2_moni.jiekou;/** * Created by Menglucywhh on 2017/11/11. */public interface DengluModelCallBack {    public void denglu_success();    public void denglu_fail();}

ZhuceViewCallBack

package com.example.a171111_zhoukao2_moni.jiekou;/** * Created by Menglucywhh on 2017/11/11. */public interface ZhuceViewCallBack {    //注册判断非空    public void zhu_phone_empty();    public void zhu_pass_empty();    public void zhu_success();    public void zhu_fail();}

ZhuceModelCallBack

package com.example.a171111_zhoukao2_moni.jiekou;/** * Created by Menglucywhh on 2017/11/11. */public interface ZhuceModelCallBack {    public void zhuce_success();}

LoginViewCallBack

package com.example.a171111_zhoukao2_moni.jiekou;/** * Created by Menglucywhh on 2017/11/11. */public interface LoginViewCallBack {    //登陆判断非空    public void deng_phone_empty();    public void deng_pass_empty();    public void deng_success();    public void deng_fail();}

MyModel

package com.example.a171111_zhoukao2_moni.model;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import com.example.a171111_zhoukao2_moni.helper.MyOpenHelper;import com.example.a171111_zhoukao2_moni.jiekou.DengluModelCallBack;import com.example.a171111_zhoukao2_moni.jiekou.ZhuceModelCallBack;/** * Created by Menglucywhh on 2017/11/11. */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();        }    }}


MyPresenter

package com.example.a171111_zhoukao2_moni.presenter;import android.content.Context;import android.support.v4.app.FragmentActivity;import android.text.TextUtils;import com.example.a171111_zhoukao2_moni.fragment.DengluFragment;import com.example.a171111_zhoukao2_moni.fragment.ZhuceFragment;import com.example.a171111_zhoukao2_moni.jiekou.DengluModelCallBack;import com.example.a171111_zhoukao2_moni.jiekou.LoginViewCallBack;import com.example.a171111_zhoukao2_moni.jiekou.ZhuceModelCallBack;import com.example.a171111_zhoukao2_moni.jiekou.ZhuceViewCallBack;import com.example.a171111_zhoukao2_moni.model.MyModel;import com.google.gson.JsonSyntaxException;/** * Created by Menglucywhh on 2017/11/11. */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


package com.example.a171111_zhoukao2_moni.adapter;import android.content.Context;import android.content.Intent;import android.support.v7.widget.RecyclerView;import android.view.View;import android.view.ViewGroup;import android.widget.ImageView;import android.widget.TextView;import com.example.a171111_zhoukao2_moni.R;import com.example.a171111_zhoukao2_moni.ThirdActivity;import com.example.a171111_zhoukao2_moni.bean.RecyBean;import com.example.a171111_zhoukao2_moni.fragment.LieBiaoFragment;import com.nostra13.universalimageloader.core.ImageLoader;import java.util.ArrayList;import java.util.List;/** * Created by Menglucywhh on 2017/11/11. */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);        }    }}


recy_item布局

<?xml version="1.0" encoding="utf-8"?><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>


secondActivity

<?xml version="1.0" encoding="utf-8"?><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>

secondActivity

package com.example.a171111_zhoukao2_moni;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.RadioGroup;import android.widget.RelativeLayout;import android.widget.Toast;import com.example.a171111_zhoukao2_moni.fragment.DengluFragment;import com.example.a171111_zhoukao2_moni.fragment.GeRenFragment;import com.example.a171111_zhoukao2_moni.fragment.LieBiaoFragment;import com.example.a171111_zhoukao2_moni.fragment.ZhuceFragment;import com.tencent.connect.UserInfo;import com.tencent.connect.auth.QQToken;import com.tencent.connect.common.Constants;import com.tencent.tauth.IUiListener;import com.tencent.tauth.Tencent;import com.tencent.tauth.UiError;import org.json.JSONObject;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();            }        });    }}

MyOpenHrlper

package com.example.a171111_zhoukao2_moni.helper;import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;/** * Created by Menglucywhh on 2017/11/11. */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) {    }}

布局third

<?xml version="1.0" encoding="utf-8"?><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>

ThirdActivity


package com.example.a171111_zhoukao2_moni;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;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);    }}

App

package com.example.a171111_zhoukao2_moni.appli;import android.app.Application;import com.nostra13.universalimageloader.core.ImageLoader;import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;/** * Created by Menglucywhh on 2017/11/11. */public class App extends Application {    @Override    public void onCreate() {        super.onCreate();        ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build();        ImageLoader.getInstance().init(configuration);    }}




okhttp