Value in edittext don't show until it get focus. Android
Asked Answered
O

2

12

I'm building an app that get its layout based on external data. The layout is split into different blocks depending on the indata. These blocks are displayed with the help of a viewflipper. In each block there is, for the time being, one or more "textview" and "edittext". On the first page of the flipper all data is showing as it should in the textviews and edittexts. But on the other pages in the viewflipper the value in the edittexts is not showing until the edittext get focused. I have no idea why. So to be clear. The values for all edittexts is actually there, but doesn't show until the edittext get focused. The problem is the same on all devices I have runned the app on (emulator, HTC Desire, HTC Wildfire). Does anyone know how to fix this problem?

Here is the class that generate the layout:

public class ModuleLayout extends LinearLayout {

public ModuleLayout(Context context, ArrayList<BaseModuleItem> itemList) {
    super(context);
    TableLayout tempTable = new TableLayout(context);

        for (int i = 0; i < itemList.size(); i++)
        {
            TableRow tempRow = new TableRow(context);
            TextView tempTextView = new TextView(context);
            tempTextView.setText(itemList.get(i).getName());

            EditText tempEditText = new EditText(context);
            tempEditText.setText(itemList.get(i).getItemValue());

            tempRow.addView(tempTextView);
            tempRow.addView(tempEditText);

            tempTable.addView(tempRow);
        }

        tempTable.setColumnStretchable(1, true);
        this.addView(tempTable);
    }
}

Here is a picture of the problem in action.

The left picture displays all its values fine. The right picture is on the second position in the viewflipper and does not display the values in the edittexts, with the exception for the first that have focus. I should also mention that after an edittext has gotten focus it continues to display the value even if I fling to other views in the viewflipper and then back.

Ossiferous answered 5/5, 2011 at 12:36 Comment(3)
Are you able to post the complete minimal code necessary to replicate your problem?Nelia
I think i have narrowed down the the problem to the viewflipper there these widets populate. I have no problem with it if I tell the viewflipper to display the next view by running the command SetCurrentView(int);. The problem is when I do the fling (animate the view to follow my finger). I'm plying around with the parameters "gone", "invisible" and "visible". I will post the code when I have time. I need to trim it down allot before I can post it here.Ossiferous
Did you ever resolve this issue?Silicic
S
1

That Layout from how it appears here is not on the UI thread meaning no matter what you change you won't see anything until the UI thread (also known as the Main Thread) updates. The UI/Main thread is what all your activities run through so it's easy to think that stuff just updates automatically (since most of the previous work you have done is also somewhere within the Activity, I am assuming). The onFocusChanged event (clicking in the edittext) will update the UI thread by calling invalidate() on itself. You can force it to update by calling EditText.invalidate() if you need to, but it's usually best to have it update naturally after creation. Without seeing the rest of your code this is the best I can do for you, I hope this helps :)

Smackdab answered 12/9, 2011 at 19:40 Comment(0)
B
0

Having not seeing your full code I'm making a bit of a guess-suggestion but have you tried textView.invalidate() (if calling from GUI thread) or textView.postInvalidate() (if calling from another thread)?

Bernetta answered 1/9, 2011 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.