3

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?

Kaushik
  • 6,150
  • 5
  • 39
  • 54
Tobey66
  • 73
  • 9

1 Answers1

0

Why didnt the somewhat-error that helped me to get this fixed, appear earlier so i didt need to ask this Question?

The error was: "Skipped 300 frames! The application may be doing too much work on its main thread"

Which brought me to: The application may be doing too much work on its main thread

So i removed most of the stuff from RunOnUiThread and now it works. Only 2 Textviews appeared because i had y < 200 set to low for more textviews to appear.

Community
  • 1
  • 1
Tobey66
  • 73
  • 9