I already spent hours searching and trying, but i cant get on the right path.
First my Code:
public class MyThreadLoc extends Thread{
Context context;
final ViewGroup view;
MyThreadLoc(Context context){
super();
this.context = context;
view = (ViewGroup) findViewById(R.id.mLayout);
}
int height;
@Override public void run() {
Looper.prepare();
int i = 0;
int y = 10;
while(running && i < 20){
i++;
if(y >= 200){
runOnUiThread(new Runnable() {
public void run() {
view.removeAllViews();
view.setBackgroundColor(Color.BLACK);
}
});
y=10;
}
try {
Thread.sleep( 500 );
Log.d("mystuff", "Sleep");
} catch ( InterruptedException e ) { e.printStackTrace(); }
final ViewGroup.LayoutParams lParam = new ViewGroup.LayoutParams(500,30); //MATCH_PARENT, 30);
while(y < 200 && running){
final float yb = y;
runOnUiThread(new Runnable() {
TextView tview;
public void run() {
Log.d("mystuff", "innerrun");
synchronized (view){
tview = new TextView(context);
tview.setText("Test");
tview.setY(yb);
view.addView(tview, lParam);
height = tview.getHeight();
view.updateViewLayout(tview, new RelativeLayout.LayoutParams(500,30));
Log.d("mystuff", Integer.toString(view.getChildCount()));
try {
Thread.sleep( 50 );
Log.d("mystuff", "Sleep");
} catch ( InterruptedException e ) { e.printStackTrace(); }
}
}
});
y = y + 100; //height +5;
}
The View doesn't appear first, but in the end 2 textviews with "Test" appear. How can I update it, so that I see every single textview appearing?