Zardaloop
Zardaloop

Reputation: 1624

layout update fail when it is called in oncreat()method

I have an issue with layout update. I have method like this :

public  void changeview(){
    tabHost.getTabWidget().getChildAt(1).setVisibility(View.GONE);
    tabHost.getTabWidget().getChildAt(2).setVisibility(View.GONE);
    tabHost.getTabWidget().getChildAt(3).setVisibility(View.VISIBLE);
    tabHost.getTabWidget().getChildAt(0).setVisibility(View.VISIBLE);

    try{
        periodicCheck.setVisibility(View.GONE);
        periodiCheckText.setVisibility(View.GONE);
        MessageDelayText.setVisibility(View.GONE);
    }catch (Exception e) {
        throw new Error("set visibility failed: "+e);
    }

When I call the method from button 's click listener it works fine, but when I call the method within the oncreate() method of Acitivity class nothing happens.

I am just wondering maybe I need to refresh the layout but I am not sure?? I have tried to use invalidate mthod by implementing the following code, but still nothinf happens.

ViewGroup vg = (ViewGroup) findViewById (R.id.main);
vg.invalidate();

I would appreciate any advice on that.

Many thanks in advance

Upvotes: 1

Views: 84

Answers (1)

Andro Selva
Andro Selva

Reputation: 54322

Call this from the onWindowFocusChanged(). This is actually a abstract method of the Activity which will be called once your View is drawn. Override this to your Activity and check,

@Override
public void onWindowFocusChanged(boolean hasFocus) {
changeview();
super.onWindowFocusChanged(hasFocus);
}

Upvotes: 2

Related Questions