Sorin Grecu
Sorin Grecu

Reputation: 1034

How to ignore GONE editTexts?

I have some code that adds EditTexts dynamically(when last is focused, it creates a new one) and sets their text to their pozition in the linear layout. For example : there are 3 edittexts created,their texts will be 1,2 and 3. And so on.

It all works great but i have a button that sets their visibility to GONE.This is where the problem arises.If i have lets say 5 edittexts with the texts 1,2,3,4,5 if i delete number 2 for example,it won't say 1,2,3,4 but 1,3,4,5.I guess it sets the number to the GONE view,even if it's no longer there,i know that.

I tried different ways,.getVisibility,in case the view is GONE,don't set a number to it, and other ways i can't even remember,none worked. Here's how i set the text,there has to be a way to ignore GONE views.

for(int kz=0;kz<l0.getChildCount();kz++)    {

        edtxt=(EditText) l0.getChildAt(kz);
            edtxt.setText((kz+1)+"");

Upvotes: 0

Views: 51

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

If I have not misunderstood you:

int counter = 1;
for(int kz=0; kz < l0.getChildCount();kz++) {

    edtxt=(EditText) l0.getChildAt(kz);

    int visibility = edtxt.getVisibility(); 
    if (visibility == View.GONE)
       continue;
    edtxt.setText(counter++ +"");

}

Upvotes: 1

Related Questions