Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
TextView[] t = new TextView[8];
t[0] = (EditText)findViewById(;
t[1] = (EditText)findViewById(;
t[2] = (EditText)findViewById(;
t[3] = (EditText)findViewById(;
t[4] = (EditText)findViewById(;
t[5] = (EditText)findViewById(;
t[6] = (EditText)findViewById(;
t[7] = (EditText)findViewById(;

And Go On

What I have tried:

t[i] = (EditText)findViewById(;
repeating many times in my code so i am trying to replace seller1,seller2.... by some sort of array of selleri. So i have try
String[] Seller = {"seller1","seller2","seller3","seller4"};
and replace it in
t[i] = (EditText)findViewById([i]);
but gives error on seller[i].
Updated 5-May-23 22:23pm

As you can see from your calls to findViewById, you cannot use strings to reference resources, you must use the actual resource identifiers. So you could try something like:
int[] Sellers = {,,,, ...};
// and replace it in 
t[i] = (EditText) findViewById(Sellers[i]);
But all of this begs the question: do you really need EditText types for this, or could a List<T> work better?
Share this answer
Vivek Kansal 24-Sep-20 12:47pm    
Not working sir. How List<t> can replace EditText? Is there any example?
Richard MacCutchan 24-Sep-20 16:50pm    
I have no idea, you need to think about what you are trying to do and whether your design is the best way of doing it. Go to the Android developer website and look at the documentation, it contains all the information you need.
Sandeep Mewara 24-Sep-20 17:14pm    
5! Above suggested code snippet makes sense and should work (array with actual IDs)
If you have fixed naming convention then code like below would be easier instead of defining an array with all IDs.

ArrayList<EditText> myList = new ArrayList<EditText>();

// Removed array
String sellerID;
int resourceViewID; 

for (int i = 0; i < 4; i++)
   sellerID = "seller" + i;
   resourceViewID = getResources().getIdentifier(sellerID, "id", getPackageName());

Reference: Java ArrayList[^]
The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
Share this answer
Richard MacCutchan 24-Sep-20 16:56pm    
"// All viewIds here - can be any ID"
Yes, but they are not Strings.
Sandeep Mewara 24-Sep-20 17:12pm    
Thanks. Yes, I updated with the change. We can find that ID using string and use it. :thumbsup:
Richard MacCutchan 24-Sep-20 17:20pm    
Something new I learnt today. +5.
Abisay 16-Oct-23 17:11pm    
How do we call the data? With mylist?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900