这是我的代码,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);
}
答案 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();
}
这应该适合你。