#Waiting for View to refresh

12 messages · Page 1 of 1 (latest)

eager flax
#

I am trying to get an ImageView to show up in a RelativeLayout before the code continues. I have tried multiple ways to get a thread to add the IV to the RL but it also does not want to manipulate UI because it isn't the UIThread. Is there a way to create a RL in a Thread that shows up on the MainActivity Layout or can i force the UIThread to load the RL first somehow?


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Button with ClickListener
        findViewById(R.id.b1).setOnClickListener(bListener);
    }

    View.OnClickListener bListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Post ImageView to a RelativeLayout
            RelativeLayout canvas = findViewById(R.id.relativeLayout);
            ImageView iv = new ImageView(MainActivity.this);
            iv.setImageResource(R.drawable.ic_launcher_foreground);
            canvas.addView(iv);
            //Have ImageView show up here before thread continues
            while(true){}
        }
    };
}```
solar pagodaBOT
#

This post has been reserved for your question.

Hey @eager flax! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

primal dawn
#

what does that while true do?

#

seems like that would just stop your program from working

eager flax
#

It is there for testing purposes. I want the programm to have the view update till then. If not, the thread is locked so that it wont happen in the idle time after the OnClicklistener

#

In the original Problem i am creating and animating ImageViews in a for loop, but every Creation and Animation is supposed to be done before the next one starts

primal dawn
#

also isn't there Activity.runOnUiThread

eager flax
#

But i dont understand how i would use that thread to make the UiThread update the RL before continuing

primal dawn
#

You're saying you want to wait the entire program to update the UI? Aren't you doing it anyway when you update the UI?

#

Or do you want to wait a certain amount of time after updating it