月考1

依赖

 compile 'com.google.code.gson:gson:2.2.4'

    compile 'com.android.support:design:26.+'

    implementation 'com.squareup.okhttp3:okhttp:3.11.0'

    implementation 'com.squareup.picasso:picasso:2.71828'

    compile 'com.fyales.android:library:1.0.2'

package com.example.widge;

//////////////////////////////////////////////////////////////////////// 

 

/**

 * Created by lenovo on 2018/8/24.

 */

 

public class togglebutton extends LinearLayout implements View.OnClickListener {

 

    private Button jian;

    private Button add1;

    private TextView number;

 

    public togglebutton(Context context) {

        super(context);

    }

 

    public togglebutton(Context context, @Nullable AttributeSet attrs) {

        super(context, attrs);

        initview(context);

    }

 

    private void initview(Context context) {

        LayoutInflater.from(context).inflate(R.layout.include3,this);

        jian = findViewById(R.id.jian);

        add1 = findViewById(R.id.add1);

        number = findViewById(R.id.number);

        jian.setOnClickListener(this);

        add1.setOnClickListener(this);

 

    }

 

    @Override

    public void onClick(View view) {

        String s = number.getText().toString();

        int i = Integer.parseInt(s);

        switch (view.getId()){

            case  R.id.jian:

                if(i<=1){

                    Toast.makeText(getContext(),"不能小于1",Toast.LENGTH_LONG).show();

                }

                i-=1;

                number.setText(String.valueOf(i));

                break;

            case  R.id.add1:

                i+=1;

                number.setText(String.valueOf(i));

                break;

        }

    }

}

///////////////////////Seconed

public class Second extends AppCompatActivity implements View.OnClickListener {

    private  String path ="http://www.zhaoapi.cn/product/getCarts?uid=71";

    private RecyclerView recycle;

    private CheckBox cb_01;

    private Button zf;

    private  myadapter myadapter;

    private  List<com.example.bean.news.DataBean> data;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_second);

        recycle = findViewById(R.id.recycle);

        cb_01 = findViewById(R.id.cb_01);

        zf = findViewById(R.id.zf);

        cb_01.setOnClickListener(this);

        getfromnet();

    }

 

    private void getfromnet() {

        Request request = new Request.Builder().url(path).build();

        OkHttpClient okHttpClient = new OkHttpClient();

        Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {

            @Override

            public void onFailure(Call call, IOException e) {

                 //不做任何操作

            }

            @Override

            public void onResponse(Call call, Response response) throws IOException {

                final String json = response.body().string();

                runOnUiThread(new Runnable() {

                    @Override

                    public void run() {

                        Gson gson = new Gson();

                        news news = gson.fromJson(json, news.class);

                        data = news.getData();

                        //创建适配器

                        myadapter = new myadapter(Second.this,data);

                        LinearLayoutManager manager = new LinearLayoutManager(Second.this, LinearLayoutManager.VERTICAL, false);

                        recycle.setLayoutManager(manager);

                        recycle.setAdapter(myadapter);

                    }

                });

            }

        });

 

    }

 

    @Override

    public void onClick(View view) {

        switch (view.getId()){

            case R.id.cb_01:

               if(cb_01.isChecked()){

                   for (int i = 0; i <data.size() ; i++) {

                       data.get(i).setChecked(true);

                       for (int j = 0; j < data.get(i).getList().size(); j++) {

                           data.get(i).getList().get(j).setChecked(true);

                       }

                   }

               }else {

                   for (int i = 0; i <data.size() ; i++) {

                       data.get(i).setChecked(false);

                       for (int j = 0; j < data.get(i).getList().size(); j++) {

                           data.get(i).getList().get(j).setChecked(false);

                       }

 

                   }

               }

               myadapter.notifyDataSetChanged();

                break;

        }

    }

}

///////activity

public class MainActivity extends AppCompatActivity {

 

    private TagCloudLayout container;

    private ArrayList<String> mList;

    private TagBaseAdapter mAdapter;

    private EditText edit_text;

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        //初始化

        container = findViewById(R.id.container1);

        edit_text = findViewById(R.id.edit_text);

        mList = new ArrayList<>();

        mList.add("中华人民共和国");

        mList.add("大韩民国");

        mList.add("日本");

        mList.add("朝鲜");

        mList.add("台湾");

        mList.add("香港特别行政区");

        mList.add("澳门特别行政区");

        mList.add("越南");

        mList.add("老挝");

        mList.add("柬埔寨");

        mList.add("泰国");

        mList.add("缅甸");

        mList.add("马来西亚");

        mList.add("新加坡");

        mList.add("印度尼西亚");

        mList.add("文莱");

        mList.add("菲律宾");

        mAdapter = new TagBaseAdapter(this, mList);

        findViewById(R.id.add_btn).setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                //获取值

                String s = edit_text.getText().toString();

                mList.add(s);

                mAdapter.notifyDataSetChanged();

            }

        });

        container.setAdapter(mAdapter);

        container.setItemClickListener(new TagCloudLayout.TagItemClickListener() {

            @Override

            public void itemClick(int position) {

                Toast.makeText(MainActivity.this, mList.get(position),Toast.LENGTH_SHORT).show();

                Intent intent = new Intent(MainActivity.this, Second.class);

                startActivity(intent);

                finish();

            }

        });

    }

}

 

/**

 * Created by lenovo on 2018/8/24.

 */

///////////// adapter

public class myadapter extends RecyclerView.Adapter<myadapter.oneholder> {

    private Context context;

    private List<news.DataBean> list;

 

    public myadapter(Context context, List<news.DataBean> list) {

        this.context = context;

        this.list = list;

    }

 

    @Override

    public oneholder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.include1, null);

        oneholder oneholder = new oneholder(view);

        return oneholder ;

    }

 

    @Override

    public void onBindViewHolder(oneholder holder, int position) {

        holder.cb_02.setText(list.get(position).getSellerName());

        LinearLayoutManager manager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);

        holder.recycle2.setLayoutManager(manager);

        myadapter1 myadapter1 = new myadapter1(context,list.get(position).getList());

        holder.cb_02.setChecked(list.get(position).isChecked());

        holder.recycle2.setAdapter(myadapter1);

    }

 

    @Override

    public int getItemCount() {

        return list.size();

    }

    class  oneholder extends  RecyclerView.ViewHolder{

 

        private final RecyclerView recycle2;

        private final CheckBox cb_02;

 

        public oneholder(View itemView) {

            super(itemView);

            recycle2 = itemView.findViewById(R.id.recycle2);

            cb_02 = itemView.findViewById(R.id.cb_02);

        }

    }

}

/**

 * Created by lenovo on 2018/8/24.

 */

 

public class myadapter1 extends RecyclerView.Adapter<myadapter1.oneholder> {

 

    private  Context context;

    private  List<news.DataBean.ListBean> list;

 

    public myadapter1(Context context, List<news.DataBean.ListBean> list) {

        this.context = context;

        this.list = list;

    }

 

    @Override

    public oneholder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.include2,null);

        oneholder oneholder = new oneholder(view);

        return oneholder;

    }

 

    @Override

    public void onBindViewHolder(oneholder holder, int position) {

        holder.title1.setText("单价是:"+list.get(position).getPrice());

        String images = list.get(position).getImages();

            if(images!=null&&images.contains("|")){

                String[] strings = images.split("\\|");

                for (int i = 0; i <strings.length ; i++) {

                    Picasso.get().load(strings[i]).into(holder.img);

                }

            }else {

                Picasso.get().load(images).into(holder.img);

            }

       holder.cb_03.setChecked(list.get(position).isChecked());

    }

 

    @Override

    public int getItemCount() {

        return list.size();

    }

    class  oneholder extends  RecyclerView.ViewHolder{

 

        private final CheckBox cb_03;

        private final ImageView img;

        private final TextView title1;

 

        public oneholder(View itemView) {

            super(itemView);

            cb_03 = itemView.findViewById(R.id.cb_03);

            img = itemView.findViewById(R.id.img);

            title1 = itemView.findViewById(R.id.title1);

        }

    }

}

/**

include3

**

/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent">
<Button
android:id="@+id/jian"
android:text="-"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/number"
android:text="1"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/add1"
android:textSize="20sp"
android:text="+"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

/***

**include2

**/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/cb_03"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/img"
android:src="@mipmap/ic_launcher"
android:layout_width="70dp"
android:layout_height="70dp" />
<TextView
android:id="@+id/title1"
android:text="title1"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<com.example.widge.togglebutton
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

/*

*include1

**/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/cb_02"
android:text="商家一"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>、

/*

*activity_seconde

**/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.day18rikao02.Second">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_weight="9" />
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<CheckBox
android:id="@+id/cb_01"
android:text="全选/不选"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/tv_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/cb_01"
android:layout_marginLeft="69dp"
android:layout_marginStart="69dp"
android:layout_toEndOf="@+id/cb_01"
android:layout_toRightOf="@+id/cb_01"
android:text="结算"
android:textSize="20sp" />
<Button
android:id="@+id/zf"
android:text="支付"
android:textSize="20sp"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>

 

/****

*activity_anim

*/

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.example.day18rikao02.MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edit_text"
android:layout_weight="8"
android:hint="请输入关键字"
android:layout_width="0dp"
android:layout_height="match_parent" />
<Button
android:text="搜索"
android:id="@+id/add_btn"
android:textSize="20sp"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
<com.fyales.tagcloud.library.TagCloudLayout
android:id="@+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tagSpacing="15dp"
app:lineSpacing="10dp"/>

</LinearLayout>

posted @ 2018-08-24 21:39  失落的城市  阅读(112)  评论(0)    收藏  举报