从微调器中提取数据并将其显示在新的活动上

时间:2018-06-21 16:55:05

标签: android android-studio spinner

我已经在这个项目上工作了一段时间,我无法将所有数据显示在活动的下一页上。我在一个页面上有12个微调器,并且我需要所有这些数据才能在下一个“活动”页面上以12个不同的textview显示。我有它,以便它使用按钮在页面之间移动。数据确实显示。仅当它是最后选择的项目并且我需要显示所有12个数据点时。如果不显示数据,则为空。这是我正在使用的一些代码。请帮忙。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_page5);
   /* Bundle extra = getIntent().getExtras();
    String Sent;
    Sent = extra.getString("Sent");
    tv.setText("Sensor Type: "+ Sent);*/




    tv = (TextView)findViewById(R.id.textViewCustName);
    tv1 = (TextView)findViewById(R.id.textViewCustomer_id);
    tv2 = (TextView)findViewById(R.id.textViewProloID);
    tv3 = (TextView)findViewById(R.id.textViewProloname);
    tv4 = (TextView)findViewById(R.id.textViewSent);
    tv5 = (TextView)findViewById(R.id.textViewSenid);
    tv6 = (TextView)findViewById(R.id.textViewVename);
    tv7 = (TextView)findViewById(R.id.textViewVenid);
    tv8 = (TextView)findViewById(R.id.textView2);
    tv9 = (TextView)findViewById(R.id.textView3);
    tv10 = (TextView)findViewById(R.id.textView4);


    Intent intent = getIntent();
    value = intent.getStringExtra("Sensor Type");
    tv.setText("Sensor Type:" + value);


    Intent two = getIntent();
    message = two.getStringExtra("Sensor ID");
    tv1.setText("Sensor ID:" + message);


    Intent three = getIntent();
    voice = three.getStringExtra("Vendor Name");
    tv2.setText("Vendor Name:" + voice);


    Intent four = getIntent();
    chorus = four.getStringExtra("Vendor ID");
    tv3.setText("Vendor ID:" + chorus);

这是从第一个活动开始的。请注意,我已经初始化了所有内容,而这正是我输入数据的地方

 SenType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int 
position, long id) {

            if (position==1){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                       /* final GlobalClass globalVariable = 
(GlobalClass)getApplicationContext();
                        globalVariable.setSentyp("Environment");*/

                        Intent string = new Intent(getBaseContext(), 
locateagain.class);
                        string.putExtra("Sensor Type", "Environment");
                        startActivity(string);

                       /* Intent string = new Intent(Page2ish.this, 
 locateagain.class);
                        string.putExtra("Sent", String.valueOf(SenType));
                        startActivity(string);*/
                    }
                });

            }else if (position==2){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      /*  final GlobalClass globalVariable = 
 (GlobalClass)getApplicationContext();
                        globalVariable.setSentyp("Event");*/


                       Intent string = new Intent(Page2ish.this, 
 locateagain.class);
                        string.putExtra("Sensor Type", "Event");
                        startActivity(string);
                      /*  Intent string = new Intent(Page2ish.this, 
  locateagain.class);
                        string.putExtra("Sent", String.valueOf(SenType));
                        startActivity(string);*/
                    }
                });

            }else if (position==3){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        final GlobalClass globalVariable = 
   (GlobalClass)getApplicationContext();
                        globalVariable.setSentyp("Activity");
                       /* Intent string = new Intent(Page2ish.this, 
 locateagain.class);
                        string.putExtra("Sensor Type", "Activity");
                        startActivity(string);*/

                    }
                });
            }
        }


        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    SenID.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
  {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int 
  position, long id) {
            if (position==1){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      //  
   globalVariable.setSenoid("5a7de613e13508be088dc4a8");

                        Intent senid = new Intent(Page2ish.this, 
   locateagain.class);
                        senid.putExtra("Sensor ID", 
  "5a7de613e13508be088dc4a8");
                        startActivity(senid);
                    }
                });
            }else if (position==2){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      //  
   globalVariable.setSenoid("5a7de613e13508be088dc4a8");

                        Intent senid = new Intent(Page2ish.this, 
   locateagain.class);
                        senid.putExtra("Sensor ID", 
    "5a7de7d0e13508be088dc4a9");
                        startActivity(senid);
                    }
                });
            }else if (position==3){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

     //globalVariable.setSenoid("5a7de873e13508be088dc4aa");

                        Intent senid = new Intent(Page2ish.this, 
   locateagain.class);
                        senid.putExtra("Sensor ID", 
  "5a7de873e13508be088dc4aa");
                        startActivity(senid);
                    }
                });
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    VenID.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
   {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int 
   position, long id) {
            if (position==1){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent vena = new Intent(Page2ish.this, 
    locateagain.class);
                        vena.putExtra("Vendor ID", 
   "5a7ddc2de13508be088dc4a7");
                        startActivity(vena);
                    }
                });
            }else if (position==2){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent vena = new Intent(Page2ish.this, 
   locateagain.class);
                        vena.putExtra("Vendor ID", 
  "5b10193d446f247a60c6cad6");
                        startActivity(vena);
                    }
                });
            }else if (position==3){
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent vena = new Intent(Page2ish.this, 
   locateagain.class);
                        vena.putExtra("Vendor ID", 
   "5b1e8765a629e185adddad48");
                        startActivity(vena);
                    }
                });
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

0 个答案:

没有答案