mr.low
mr.low

Reputation: 446

android layout wont show,how to force it do display?

This is my code that i have, the onActivityResult is capturing an intent that i created but my problem is that setContentView(R.laout.waiting) is not being used. R.layout.waiting is not been Display on android. Instead the screen will just go completely dark for a couple of seconds until it finish the rest of the code but it will display setContentView(tv);. how can i force android to display the layout before moving to the rest of the code.

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      super.onActivityResult(requestCode, resultCode, intent);       


      setContentView(R.layout.waiting);
      SystemClock.sleep(100000);


      IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);                      
      displayScanResults(scanResult.getContents());     
}

public void displayScanResults(String upc) {

   item.scanItem(upc );
   tv = new TextView(this);
   tv.setText( "" + item.getResults().get(0));
   setContentView(tv);    

}

Upvotes: 0

Views: 450

Answers (1)

Sukitha Udugamasooriya
Sukitha Udugamasooriya

Reputation: 2308

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  super.onActivityResult(requestCode, resultCode, intent);          
    setContentView(R.layout.waiting);
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); 
    final Activity act = this;
    Thread t = new Thread() {
    public void run() {
       try {
           sleep(10000);
       } catch (InterruptedException e) {
          // TODO Auto-generated catch block
    e.printStackTrace();
       }
       act.runOnUiThread(new Runnable() {
           public void run() {
           act.displayScanResults(scanResult.getContents());     
                }
           });
       }
    };
    t.start();
}

This should work for you.

Upvotes: 1

Related Questions