//mainactivity布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#cc3300"
android:orientation="horizontal">
<TextView
android:id="@+id/text_fh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:text="返回"
android:textColor="#fff"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="15dp"
android:text="登录"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:gravity="center"
android:orientation="vertical">
<EditText
android:id="@+id/edit_phone"
android:layout_width="400dp"
android:layout_height="60dp"
android:background="@drawable/edit_borad"
android:hint="请输入手机号" />
<EditText
android:id="@+id/edit_pass"
android:layout_width="400dp"
android:layout_height="60dp"
android:layout_marginTop="30dp"
android:inputType="textPassword"
android:background="@drawable/edit_borad"
android:hint="请输入密码" />
<TextView
android:id="@+id/text_res"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginRight="-170dp"
android:text="立即注册"
android:textColor="#cc3300"
android:textSize="15sp" />
<Button
android:id="@+id/btn_dl"
android:layout_width="400dp"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:background="#cc3300"
android:gravity="center"
android:text="登录"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
//edit_text
<?xml version="1.0" encoding="utf-8"?><stroke android:width="2dp"
android:color="#ccc"/>
//mainactivity登录
package mmy.com.bawei.mamengyun20190404;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import mmy.com.bawei.mamengyun20190404.bean.DengluBean;
import mmy.com.bawei.mamengyun20190404.mvp.model.MainModelIml;
import mmy.com.bawei.mamengyun20190404.mvp.presenter.MainPresenterIml;
import mmy.com.bawei.mamengyun20190404.mvp.view.MainView;
public class MainActivity extends AppCompatActivity implements MainView, View.OnClickListener {
private TextView text_res;
private Button btn_dl;
private EditText edit_phone;
private EditText edit_pass;
private MainPresenterIml mainPresenterIml;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit_phone = (EditText) findViewById(R.id.edit_phone);
edit_pass = (EditText) findViewById(R.id.edit_pass);
findViewById(R.id.btn_dl).setOnClickListener(this);
findViewById(R.id.text_res).setOnClickListener(this);
mainPresenterIml = new MainPresenterIml(new MainModelIml(), this);
}
private void doLogin() {
String phone = edit_phone.getText().toString().trim();
String pass = edit_pass.getText().toString().trim();
if (TextUtils.isEmpty(phone)){
Toast.makeText(this,"不能为空",Toast.LENGTH_LONG).show();
}
if (TextUtils.isEmpty(pass)){
Toast.makeText(this,"不能为空",Toast.LENGTH_LONG).show();
}
mainPresenterIml.doDl(phone,pass);
}
@Override
public void success(String data) {
DengluBean dengluBean = new Gson().fromJson(data, DengluBean.class);
String status = dengluBean.getStatus();
if (status.equals("0000")){
startActivity(new Intent(MainActivity.this,Main2Activity.class));
}
String message = dengluBean.getMessage();
Toast.makeText(this,message,Toast.LENGTH_LONG).show();
}
@Override
public void fail(String error) {
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_dl:
doLogin();
break;
case R.id.text_res:
startActivity(new Intent(MainActivity.this,RegisterActivity.class));
break;
}
}
}
//register注册布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#cc3300"
android:orientation="horizontal">
<TextView
android:id="@+id/text_fh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:text="返回"
android:textColor="#fff"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="15dp"
android:text="注册"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:gravity="center"
android:orientation="vertical">
<EditText
android:id="@+id/edit_phone"
android:layout_width="400dp"
android:layout_height="60dp"
android:background="@drawable/edit_borad"
android:hint="请输入手机号" />
<EditText
android:id="@+id/edit_pass"
android:layout_width="400dp"
android:layout_height="60dp"
android:layout_marginTop="30dp"
android:inputType="textPassword"
android:background="@drawable/edit_borad"
android:hint="请输入密码" />
<TextView
android:id="@+id/text_dl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginRight="-170dp"
android:text="立即登录"
android:textColor="#cc3300"
android:textSize="15sp" />
<Button
android:id="@+id/btn_zc"
android:layout_width="400dp"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:background="#cc3300"
android:gravity="center"
android:text="注册"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
//register注册
package mmy.com.bawei.mamengyun20190404;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import mmy.com.bawei.mamengyun20190404.bean.RegisterBean;
import mmy.com.bawei.mamengyun20190404.mvp.model.MainModelIml;
import mmy.com.bawei.mamengyun20190404.mvp.presenter.MainPresenterIml;
import mmy.com.bawei.mamengyun20190404.mvp.view.MainView;
public class RegisterActivity extends AppCompatActivity implements MainView, View.OnClickListener {
private EditText edit_phone;
private EditText edit_pass;
private TextView text_fh;
private TextView text_dl;
private Button btn_zc;
private MainPresenterIml mainPresenterIml;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
edit_phone = (EditText) findViewById(R.id.edit_phone);
edit_pass = (EditText) findViewById(R.id.edit_pass);
text_fh = (TextView) findViewById(R.id.text_fh);
findViewById(R.id.text_dl).setOnClickListener(this);
findViewById(R.id.btn_zc).setOnClickListener(this);
text_fh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
mainPresenterIml = new MainPresenterIml(new MainModelIml(), this);
}
private void doRegister() {
String phone = edit_phone.getText().toString().trim();
String pass = edit_pass.getText().toString().trim();
if (TextUtils.isEmpty(phone)) {
Toast.makeText(this, "不能为空", Toast.LENGTH_LONG).show();
}
if (TextUtils.isEmpty(pass)) {
Toast.makeText(this, "不能为空", Toast.LENGTH_LONG).show();
}
mainPresenterIml.doZc(phone, pass);
}
@Override
public void success(String data) {
RegisterBean registerBean = new Gson().fromJson(data, RegisterBean.class);
String status = registerBean.getStatus();
if (status.equals("0000")) {
startActivity(new Intent(RegisterActivity.this, MainActivity.class));
}
String message = registerBean.getMessage();
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
@Override
public void fail(String error) {
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_zc:
doRegister();
break;
case R.id.text_dl:
startActivity(new Intent(RegisterActivity.this, MainActivity.class));
break;
}
}
}
//首页Main2Activity布局
<?xml version="1.0" encoding="utf-8"?><com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/bottomTabbar"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.hjm.bottomtabbar.BottomTabBar>
//首页
package mmy.com.bawei.mamengyun20190404;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.hjm.bottomtabbar.BottomTabBar;
import mmy.com.bawei.mamengyun20190404.fragment.Fragment1;
import mmy.com.bawei.mamengyun20190404.fragment.Fragment2;
import mmy.com.bawei.mamengyun20190404.fragment.Fragment3;
public class Main2Activity extends AppCompatActivity {
private BottomTabBar bottomTabbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
bottomTabbar = (BottomTabBar) findViewById(R.id.bottomTabbar);
bottomTabbar.init(getSupportFragmentManager())
.setFontSize(10)
.setTabPadding(4,6,10)
.setChangeColor(Color.BLACK,Color.BLUE)
.addTabItem("首页",R.drawable.start_false,Fragment1.class)
.addTabItem("我的",R.drawable.see_false,Fragment2.class)
.addTabItem("啦啦",R.drawable.message_false,Fragment3.class);
}
}
//OkHttpUtils
package mmy.com.bawei.mamengyun20190404.net;
import android.os.Handler;
import android.os.Message;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class OkHttpUtils {
private int HTTP_SUCCESS = 1000;
private int HTTP_FALL = 1001;
private HttpListener mHttpListener;
public OkHttpUtils get(String url){
doHttp(url,0,null);
return this;
}
public OkHttpUtils post(String url, FormBody.Builder bodyBuilder){
doHttp(url,1,bodyBuilder);
return this;
}
private void doHttp(String url, int i, FormBody.Builder bodyBuilder) {
OkHttpClient client = new OkHttpClient();
Request.Builder builder = new Request.Builder();
if (i == 0){
builder.get();
}else {
builder.post(bodyBuilder.build());
}
builder.url(url);
Request request = builder.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Message message = Message.obtain();
message.what = HTTP_FALL;
handler.sendMessage(message);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Message message = Message.obtain();
message.obj = response.body().string();
message.what = HTTP_SUCCESS;
handler.sendMessage(message);
}
});
}
public Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == HTTP_SUCCESS){
String data = (String) msg.obj;
mHttpListener.success(data);
}else {
String error = (String) msg.obj;
mHttpListener.fail(error);
}
}
};
public void result(HttpListener mHttpListener) {
this.mHttpListener = mHttpListener;
}
public interface HttpListener{
void success(String data);
void fail(String error);
}
}
//View
package mmy.com.bawei.mamengyun20190404.mvp.view;
public interface MainView {
void success(String data);
void fail(String error);
}
//Model
package mmy.com.bawei.mamengyun20190404.mvp.model;
public interface MainModel {
public interface CallBackListener{
void success(String data);
void fail(String error);
}
void doCarShop(CallBackListener listener);
//登录
void doDl(String phone,String pwd,CallBackListener listener);
//注册
void doZc(String phone,String pwd,CallBackListener listener);
}
//ModelIml实现类
package mmy.com.bawei.mamengyun20190404.mvp.model;
import mmy.com.bawei.mamengyun20190404.net.OkHttpUtils;
import okhttp3.FormBody;
public class MainModelIml implements MainModel{
@Override
public void doCarShop(final CallBackListener listener) {
String url = “http://172.17.8.100/ks/product/getCarts?uid=51”;
new OkHttpUtils().get(url).result(new OkHttpUtils.HttpListener() {
@Override
public void success(String data) {
listener.success(data);
}
@Override
public void fail(String error) {
listener.fail(error);
}
});
}
//登录
@Override
public void doDl(String phone, String pwd, final CallBackListener listener) {
String url = "http://172.17.8.100/small/user/v1/login";
FormBody.Builder builder = new FormBody.Builder();
builder.add("phone",phone);
builder.add("pwd",pwd);
new OkHttpUtils().post(url,builder).result(new OkHttpUtils.HttpListener() {
@Override
public void success(String data) {
listener.success(data);
}
@Override
public void fail(String error) {
fail(error);
}
});
}
//注册
@Override
public void doZc(String phone, String pwd, final CallBackListener listener) {
String url = "http://172.17.8.100/small/user/v1/register";
FormBody.Builder builder = new FormBody.Builder();
builder.add("phone",phone);
builder.add("pwd",pwd);
new OkHttpUtils().post(url,builder).result(new OkHttpUtils.HttpListener() {
@Override
public void success(String data) {
listener.success(data);
}
@Override
public void fail(String error) {
fail(error);
}
});
}
}
//Presenter
package mmy.com.bawei.mamengyun20190404.mvp.presenter;
public interface MainPresenter {
void doData();
void doDl(String phone,String pwd);
void doZc(String phone,String pwd);
}
//PresnenterIml实现类
package mmy.com.bawei.mamengyun20190404.mvp.presenter;
import mmy.com.bawei.mamengyun20190404.mvp.model.MainModel;
import mmy.com.bawei.mamengyun20190404.mvp.view.MainView;
public class MainPresenterIml implements MainPresenter,MainModel.CallBackListener {
private MainModel mainModel;
private MainView mainView;
public MainPresenterIml(MainModel mainModel, MainView mainView) {
this.mainModel = mainModel;
this.mainView = mainView;
}
@Override
public void success(String data) {
mainView.success(data);
}
@Override
public void fail(String error) {
mainView.fail(error);
}
@Override
public void doData() {
mainModel.doCarShop(this);
}
//登录
@Override
public void doDl(String phone, String pwd) {
mainModel.doDl(phone,pwd,this);
}
@Override
public void doZc(String phone, String pwd) {
mainModel.doZc(phone,pwd,this);
}
public void onDestory(){
if (mainModel != null){
mainModel = null;
}
if (mainView != null){
mainView = null;
}
System.gc();
}
}
//列表展示布局
<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"></android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<CheckBox
android:id="@+id/check_qx"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="2"
android:text="全选" />
<TextView
android:id="@+id/text_zj"
android:layout_width="0dp"
android:layout_height="60dp"
android:text="00.00¥"
android:textColor="#ff6600"
android:layout_weight="3" />
<TextView
android:id="@+id/text_qjs"
android:layout_width="0dp"
android:layout_height="60dp"
android:background="#d43c3c"
android:textColor="#fff"
android:text="去结算(0)"
android:gravity="center"
android:layout_weight="2" />
</LinearLayout>
//列表展示
package mmy.com.bawei.mamengyun20190404.fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
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.CheckBox;
import android.widget.TextView;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
import mmy.com.bawei.mamengyun20190404.R;
import mmy.com.bawei.mamengyun20190404.adapter.ShopCarAdapater;
import mmy.com.bawei.mamengyun20190404.bean.ShopCarBean;
import mmy.com.bawei.mamengyun20190404.mvp.model.MainModelIml;
import mmy.com.bawei.mamengyun20190404.mvp.presenter.MainPresenterIml;
import mmy.com.bawei.mamengyun20190404.mvp.view.MainView;
public class Fragment1 extends Fragment implements MainView {
private RecyclerView recyclerView;
private ShopCarAdapater shopCarAdapater;
private MainPresenterIml mainPresenterIml;
private List<ShopCarBean.DataBean.ListBean> list = new ArrayList<>();
private List<ShopCarBean.DataBean> data1 = new ArrayList<>();
private CheckBox check_qx;
private TextView text_zj;
private TextView text_qjs;
private float sum;
private int sums;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
check_qx = (CheckBox) view.findViewById(R.id.check_qx);
text_zj = (TextView) view.findViewById(R.id.text_zj);
text_qjs = (TextView) view.findViewById(R.id.text_qjs);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
shopCarAdapater = new ShopCarAdapater(getActivity());
recyclerView.setAdapter(shopCarAdapater);
mainPresenterIml = new MainPresenterIml(new MainModelIml(), this);
mainPresenterIml.doData();
check_qx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = check_qx.isChecked();
for (int i = 0; i < data1.size(); i++) {
data1.get(i).setChecked(checked);
List<ShopCarBean.DataBean.ListBean> list = data1.get(i).getList();
for (int j = 0; j < list.size(); j++){
list.get(j).setChecked(checked);
if (checked){
float price = list.get(j).getPrice();
int num = list.get(j).getNum();
sum = sum + price * num;
sums = sums + num;
}else {
sum = 0;
sums = 0;
}
}
}
shopCarAdapater.setListm(data1);
text_zj.setText(sum+"¥");
text_qjs.setText("去结算("+sums+")");
}
});
return view;
}
@Override
public void success(String data) {
ShopCarBean shopCarBean = new Gson().fromJson(data, ShopCarBean.class);
data1 = shopCarBean.getData();
data1.remove(0);
shopCarAdapater.setListm(data1);
}
@Override
public void fail(String error) {
}
}
//适配器
package mmy.com.bawei.mamengyun20190404.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
import mmy.com.bawei.mamengyun20190404.R;
import mmy.com.bawei.mamengyun20190404.bean.ShopCarBean;
public class ShopCarAdapater extends RecyclerView.Adapter<ShopCarAdapater.ShopViewHolder>{
private List<ShopCarBean.DataBean> list = new ArrayList<>();
private Context context ;
public ShopCarAdapater(Context context) {
this.context = context;
}
@NonNull
@Override
public ShopViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = View.inflate(context, R.layout.item_list, null);
ShopViewHolder shopViewHolder = new ShopViewHolder(view);
return shopViewHolder;
}
@Override
public void onBindViewHolder(@NonNull ShopViewHolder shopViewHolder, int i) {
shopViewHolder.text_sp.setText(list.get(i).getSellerName());
shopViewHolder.check_sj.setChecked(list.get(i).isChecked());
List<ShopCarBean.DataBean.ListBean> list = this.list.get(i).getList();
ShopAdapter shopAdapter = new ShopAdapter(context,list);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
shopViewHolder.recyclerView1.setLayoutManager(linearLayoutManager);
shopViewHolder.recyclerView1.setAdapter(shopAdapter);
}
@Override
public int getItemCount() {
return list.size();
}
public void setListm(List<ShopCarBean.DataBean> data1) {
this.list = data1;
notifyDataSetChanged();
}
public class ShopViewHolder extends RecyclerView.ViewHolder{
private CheckBox check_sj;
private RecyclerView recyclerView1;
private TextView text_sp;
public ShopViewHolder(@NonNull View itemView) {
super(itemView);
text_sp = (TextView) itemView.findViewById(R.id.text_sp);
recyclerView1 = itemView.findViewById(R.id.recyclerView1);
check_sj = itemView.findViewById(R.id.check_sj);
}
}
}
//适配器布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/check_sj"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/text_sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
//子适配器
package mmy.com.bawei.mamengyun20190404.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
import mmy.com.bawei.mamengyun20190404.R;
import mmy.com.bawei.mamengyun20190404.bean.ShopCarBean;
public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ShopViewholder>{
private Context context;
private List<ShopCarBean.DataBean.ListBean> list = new ArrayList<>();
private OnCallBackListener listener;
public ShopAdapter(Context context, List<ShopCarBean.DataBean.ListBean> list) {
this.context = context;
this.list = list;
}
public void setList(List<ShopCarBean.DataBean.ListBean> list) {
this.list = list;
notifyDataSetChanged();
}
@NonNull
@Override
public ShopViewholder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = View.inflate(context, R.layout.item_list1, null);
ShopViewholder shopViewholder = new ShopViewholder(view);
return shopViewholder;
}
@Override
public void onBindViewHolder(@NonNull ShopViewholder shopViewholder, int i) {
Glide.with(context).load(list.get(i).getImages()).into(shopViewholder.image);
shopViewholder.text_bt.setText(list.get(i).getSubhead());
shopViewholder.text_jg.setText(list.get(i).getPrice()+"");
shopViewholder.check_sp.setChecked(list.get(i).isChecked());
}
@Override
public int getItemCount() {
return list.size();
}
public class ShopViewholder extends RecyclerView.ViewHolder{
private CheckBox check_sp;
private ImageView image;
private TextView text_bt;
private TextView text_jg;
public ShopViewholder(@NonNull View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.image);
text_bt = (TextView) itemView.findViewById(R.id.text_bt);
text_jg = (TextView) itemView.findViewById(R.id.text_jg);
check_sp = (CheckBox) itemView.findViewById(R.id.check_sp);
}
}
public void setCallBackListener(OnCallBackListener listener) {
this.listener = listener;
}
public interface OnCallBackListener{
void changeData(List<ShopCarBean.DataBean.ListBean> list);
}
}
//子适配器布局
<?xml version="1.0" encoding="utf-8"?><CheckBox
android:id="@+id/check_sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<ImageView
android:id="@+id/image"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="5dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/text_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
<TextView
android:id="@+id/text_jg"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:textColor="#ff6600" />
</LinearLayout>
//自定义View水波纹view类
package mmy.com.bawei.mamengyun20190404.zview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
public class WaterView extends View {
private Path mPath;
private Paint mPaint;
private float xM;
public WaterView(Context context) {
super(context);
init(context);
}
public WaterView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
mPath = new Path();
mPaint = new Paint();
mPaint.setColor(Color.BLUE);
mPaint.setStrokeWidth(80);
mPaint.setAntiAlias(true);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPath.reset();
mPath.moveTo(getLeft(), getBottom());
float mPi = (float) (Math.PI * 2 / getRight());
xM -= 0.1f;
for (int x = 0; x < getRight(); x += 20) {
float y = (float) (10 * Math.sin(mPi * x + xM) + 10);
mPath.lineTo(x, y);
}
mPath.lineTo(getRight(), getBottom());
canvas.drawPath(mPath, mPaint);
postInvalidateDelayed(50);
}
}
//布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:gravity="center"
android:background="#cc3300"
android:orientation="vertical">
<ImageView
android:id="@+id/image_m"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:text="登录" />
</LinearLayout>
<mmy.com.bawei.mamengyun20190404.zview.WaterView
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginTop="30dp" />
<Button
android:id="@+id/btn_sx"
android:text="属性动画"
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
//动画activity
package mmy.com.bawei.mamengyun20190404.fragment;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.NonNull;
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.ImageView;
import mmy.com.bawei.mamengyun20190404.R;
public class Fragment2 extends Fragment{
private ImageView image_m;
private Button btn_sx;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment2, container, false);
image_m = view.findViewById(R.id.image_m);
btn_sx = view.findViewById(R.id.btn_sx);
btn_sx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ObjectAnimator translationX = new ObjectAnimator().ofFloat(image_m,"translationX",0,0);
ObjectAnimator translationY = new ObjectAnimator().ofFloat(image_m,"translationY",0,300f);
ObjectAnimator anim = ObjectAnimator.ofFloat(image_m, "alpha", 1f, 0.3f, 0f, 0f, 0f);
AnimatorSet animatorSet = new AnimatorSet(); //组合动画
animatorSet.playTogether(translationX,translationY,anim); //设置动画
animatorSet.setDuration(5000); //设置动画时间
animatorSet.start(); //启动
}
});
return view;
}
}
//登录Bean类
package mmy.com.bawei.mamengyun20190404.bean;
public class DengluBean {
private ResultBean result;
private String message;
private String status;
public ResultBean getResult() {
return result;
}
public void setResult(ResultBean result) {
this.result = result;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public static class ResultBean {
/**
* headPic : http://172.17.8.100/images/small/default/user.jpg
* nickName : hE_6c07N
* phone : 18810857697
* sessionId : 1554368906641401
* sex : 1
* userId : 401
*/
private String headPic;
private String nickName;
private String phone;
private String sessionId;
private int sex;
private int userId;
public String getHeadPic() {
return headPic;
}
public void setHeadPic(String headPic) {
this.headPic = headPic;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
}
}
//注册bean
package mmy.com.bawei.mamengyun20190404.bean;
public class RegisterBean {
/**
* message : 该手机号已注册,不能重复注册!
* status : 1001
*/
private String message;
private String status;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
//展示bean
package mmy.com.bawei.mamengyun20190404.bean;
import java.util.List;
public class ShopCarBean {
private String msg;
private String code;
private List<DataBean> data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
private String sellerName;
private String sellerid;
private List<ListBean> list;
private boolean checked;
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public String getSellerName() {
return sellerName;
}
public void setSellerName(String sellerName) {
this.sellerName = sellerName;
}
public String getSellerid() {
return sellerid;
}
public void setSellerid(String sellerid) {
this.sellerid = sellerid;
}
public List<ListBean> getList() {
return list;
}
public void setList(List<ListBean> list) {
this.list = list;
}
public static class ListBean {
private float bargainPrice;
private String createtime;
private String detailUrl;
private String images;
private int num;
private int pid;
private float price;
private int pscid;
private int selected;
private int sellerid;
private String subhead;
private String title;
private boolean checked;
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public float getBargainPrice() {
return bargainPrice;
}
public void setBargainPrice(float bargainPrice) {
this.bargainPrice = bargainPrice;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public String getDetailUrl() {
return detailUrl;
}
public void setDetailUrl(String detailUrl) {
this.detailUrl = detailUrl;
}
public String getImages() {
return images;
}
public void setImages(String images) {
this.images = images;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public int getPscid() {
return pscid;
}
public void setPscid(int pscid) {
this.pscid = pscid;
}
public int getSelected() {
return selected;
}
public void setSelected(int selected) {
this.selected = selected;
}
public int getSellerid() {
return sellerid;
}
public void setSellerid(int sellerid) {
this.sellerid = sellerid;
}
public String getSubhead() {
return subhead;
}
public void setSubhead(String subhead) {
this.subhead = subhead;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
}
}