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){}
}
};
}```