简体   繁体   English

在Android Studio 3.4中如何将字符串值从一个活动发送到另一个活动中时如何获取所有值

[英]How Do i Get all the Values When Sending String Values from one Activity to Another in Android Studio 3.4

Please am designing an android app, i want to send (5)String values from one activity to another activity to use in different TextViews, i have tried virtually all the code i could find online on the topic, but i keep getting just one value(the last value i send in the putExtra()). 请设计一个Android应用程序,我想将(5)字符串值从一个活动发送到另一个活动以在不同的TextView中使用,我已经尝试了几乎可以在该主题上在线找到的所有代码,但我一直只获得一个值(我在putExtra()中发送的最后一个值)。 please i am new to Android Studio and will appreciate every help. 请我是Android Studio的新手,将不胜感激。

I have used the putExtra() to send one data to another activity and it worked perfectly, while trying to do the same with multiple data i keep getting just one of the data sent. 我已经使用putExtra()将一个数据发送到另一活动,并且它工作得很好,同时尝试对多个数据执行相同的操作,但我一直只收到发送的数据之一。 I have also tried using a bundle object, to receive the data from the other(recieving) activity. 我也尝试过使用bundle对象,以从其他(接收)活动中接收数据。

I expect getting all this data ( intent.putExtra("surname", "Jerry"). 我希望得到所有这些数据(intent.putExtra(“ surname”,“ Jerry”)。
intent.putExtra("middlename", "chris"). intent.putExtra(“ middlename”,“ chris”)。 intent.putExtra("lastname", "Enema")) in another activity, but i keep getting just "Enema" alone intent.putExtra(“ lastname”,“ Enema”))在另一项活动中,但我一直独自获得“ Enema”

this is my code; 这是我的代码; //in the firstActivity //在firstActivity中

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

                String sFirstname = firstname.getText().toString();
                String sLastname = lastname.getText().toString();

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

                intent.putExtra("surname" ,sFirstname);
                intent.putExtra("lastname", sLastname);

                startActivity(intent);

            }
        });

//And In the second Activity

firstname = findViewById(R.id.firstname); 名字= findViewById(R.id.firstname); lastname = findViewById(R.id.firstname); 姓= findViewById(R.id.firstname);

Intent intent = getIntent();
Bundle bundle = getIntent().getExtras();

String ssurname = bundle.getString("surname");
String slastname = bundle.getString("lastname");

firstname.setText(ssurname);
lastname.setText(slastname);

I would prefer not to ue getExtras so you should have two getExtra Like this : 我不想使用ue getExtras所以您应该有两个getExtra像这样:

 Intent intent = getIntent();

 String ssurname = intent.getExtra("surname");
 String slastname = intent.getExtra("lastname");

 firstname.setText(ssurname);
 lastname.setText(slastname);

Try this. 尝试这个。 In First Activity: 在第一个活动中:

String sFirstname = "Tope";
String sLastname = "Adebodun";

Intent theIntent = new Intent(MainActivity.this, ReceivingActivity.class);
theIntent.putExtra("firstname", sFirstname);
theIntent.putExtra("lastname", sLastname);

Then in your second activity, do this in the onCreate method: 然后在第二个活动中,在onCreate方法中执行以下操作:

Intent intent = getIntent();
String thefirst = (String) intent.getExtras.getString("firstname");
String thelast = (String) intent.getExtras.getString("lastname");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android开发中将字符串值从一个活动传递到另一个活动 - passing string values from one activity to another in android development Android Studio:如何从活动获取用户输入(从微调器和编辑文本)到另一个活动? - Android Studio: How do I get user input (From Spinner and Edit Text) from activity to another activity? 当我从另一个活动获得结果时,ListView仅更新一个视图项,如何获得所有过去的结果? - ListView is updating only one view item when I get the results from another activity, how do I get all the past results? 如何将活动中的值传递给 Android Studio 中的 class? - How do you pass values from an activity to a class in Android Studio? android studio - 如何将文本从一个活动获取到另一个活动? - android studio - how to get text from one activity to another? 从一个活动向另一个Android Studio发送两次 - Sending double from one activity to another Android Studio 如何在Android中将数据从一项活动转移到另一项活动? - How do I transfer data from one activity to another in Android? 如何在Android Studio中的另一个活动中使用一个活动的变量 - How do I use variable of one activity in another activity in android studio 如何在一个活动中将图像从ImageView发送到另一个活动中的ImageButton。 Android Studio - How can I send an image from an ImageView in one activity to an ImageButton in another activity. Android Studio 如何在另一个活动中显示从一个活动传递的值? - How to display values passing from one activity in another activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM