andriod正反传值

   正传

 Intent intent = new Intent(MilkspchoolActivity.this, MilkspchoolspshowActivity.class);
                    //传值
                    Bundle bundle1 = new Bundle();

                    //实体转json
                    Gson gsont = new Gson();
                    String userJson = gsont.toJson(mergedatas);


                    //这两句代码必须的,为的是初始化出来gson这个对象,才能拿来用
                   // builder=new GsonBuilder();
                    //gson=builder.create();


                    bundle1.putSerializable("chookList",userJson);//序列化,要注意转化(Serializable)
                    intent.putExtras(bundle1);     //将bundle传入intent中。
                    startActivityForResult(intent, 3);//注意要求码


------------------------


    //取传信息
    private void getcdata(){


        intent = getIntent();
        String action = intent.getAction();
        String TC=intent.getStringExtra("chookList");
        if(TC != null){
           // datas=intent.getStringExtra("chookList");
            //接收对象集合


            Gson gson = new Gson();
         String  strdatas=intent.getStringExtra("chookList");
            datas = gson.fromJson(strdatas, new TypeToken>(){}.getType());

        }



    }


=============================传回




        tv_go_to_pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //实体转为json

                Gson gsont = new Gson();
                String spJson = gsont.toJson(datas);


//回调
                Intent intent = new Intent(MilkspchoolspshowActivity.this, MilkUserchoolActivity.class);
                intent.putExtra("spJson", spJson);
                setResult(3, intent);
                // finish();
                finish();
                Toast.makeText(MilkspchoolspshowActivity.this,"操作删除订单:"+datas.get(0).getMilk_name(),Toast.LENGTH_LONG).show();

            }

        });



    //接收其它页面回传结果和显示图片
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


//页面传回来的值
        if (requestCode == 1)
            if (data != null) {
                //处理代码在此地
                String dataCback = data.getStringExtra("EXTRA_Colors");
                ;// 得到子窗口ChildActivity的回传数据
                // edx_color.setText(dataCback);

            }

//页面传回来的值
        if (requestCode == 3)
            if (data != null) {
                //处理代码在此地

                ;// 得到子窗口ChildActivity的回传数据---确认后的商品
                String dataCbackspJson = data.getStringExtra("spJson");
                ;// 得到子窗口ChildActivity的回传数据
              //json转实体

              //  String TC=intent.getStringExtra("chookList");

                    //接收对象集合


                    Gson gson = new Gson();
                mergedatas.clear();
                mergedatas = gson.fromJson(dataCbackspJson, new TypeToken>(){}.getType());

                //对列表得新更新
               // 按id

                for(int s=0;s

你可能感兴趣的:(linux,服务器,windows)