How to add more strings in string array with my app in android studio

Hey I'm having a problem with String array, I am using strings arrays and which is working fine now. I want to update some more string in that string array without coding in android studio, like we add photos from our mobile to app, in same manner I want to add more strings to that string array from app, is this possible?

Upvotes: 1

Views: 1333

Answers (2)

Akshatha S R
Akshatha S R

Reputation: 1345

Size of the arrays can not be changed at run time. So once you create an array of any data type, you can't add additional data at run time only you can modify the existing data. If your requirement is to add data at run time, you have to use List or ArrayList.

Ex:

List<String> list = new ArrayList<>();

for(int i = 0; i < 10; i++)
{
   list.add("item number " + (i+1));
}

You can any number of data at run time if you use a list.

Upvotes: 1

Sourabh
Sourabh

Reputation: 79

first of all share some code which you tried but failed, so that I can get an idea what you exactly want to do. 1. you can create an event listener(using button, or anything you want) 2. use list instead of a plain array 3. as soon as event is triggered fetch the string from some text-field and add it to your list

Upvotes: 0

Related Questions