F
F
FlorenceMachine2020-12-09 20:51:20
Java
FlorenceMachine, 2020-12-09 20:51:20

How to pass a string from a form to an array of strings?

Can you please tell me how to pass the string from the form to string-array, which is located in values/strings.xml?

submitButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                name = nameInput.getText().toString();
                firstName = firstNameText.getText().toString();
                lastName = lastNameText.getText().toString();


            }
        });
    }


You need to pass name, lastName, firstName

strings.xml :
<string-array name="info">
    <item></item>
    <item></item>
    <item></item>
</string-array>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2020-12-10
Hasanly @azerphoenix

And why do you need to pass a string from a form to an xml file?
Also note that if your fields are called
name
firstName
lastName
then most likely you can create an object from it. For example, (pseudocode)

User {
String name
String firstName;
String lastName;
}

And then use ArrayList. For example, List<User> users = new ArrayList();
I do not recommend using String array, since the length of the array must be determined when it is initialized. And you can technically have a different number of objects in this file.
If, on the contrary, you want to save information about the user by receiving his data from the form, then use a database (sqlite) or store them in shared preferences.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question