android布局不会显示,如何强制它显示?

时间:2010-11-11 04:40:12

标签: android layout

这是我的代码,onActivityResult正在捕获我创建的意图但是 我的问题是没有使用setContentView(R.laout.waiting)。 R.layout.waiting未在Android上显示。相反,屏幕将完全黑暗几秒钟,直到完成剩下的代码,但它将显示setContentView(tv);. 如何在移动到其余代码之前强制android显示布局。

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);    

}

1 个答案:

答案 0 :(得分:1)

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();
}

这应该适合你。