これは私のシナリオです:別のアクティビティを開くログイン画面があります。アクティビティでは、私は単純に以下を持っています:setContentViewでレイアウトをロード中にProgressDialogを表示
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
}
レイアウトは重く、いくつかのフラグメントで構成されており、ロードに約1.5秒かかります。 がレイアウトを膨張させている間に、ProgressDialog
を表示するにはどうすればよいですか?私はdoInBackground
にsetContentView
を入れてAsyncTask
を試しましたが、UIスレッドからのみUIを更新できるため、もちろんできません。 UIスレッドでsetContentView
に電話する必要がありますが、ProgressDialog
を表示/非表示する必要はありますか?
ご協力いただきありがとうございます。
フラ。
EDIT:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty_layout);
new ContentSetterTask().execute("");
}
private class ContentSetterTask extends AsyncTask<String, Void, Void> {
public ProgressDialog prgDlg;
@Override
protected void onPreExecute() {
android.os.Debug.waitForDebugger();
prgDlg = ProgressDialog.show(MultiPaneActivity.this, "", "Loading...", true);
}
@Override
protected Void doInBackground(String... args) {
android.os.Debug.waitForDebugger();
ViewGroup rootView = (ViewGroup)findViewById(R.id.emptyLayout);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflated = inflater.inflate(R.layout.activity_details, rootView);
return null;
}
@Override
protected void onPostExecute(Void arg) {
android.os.Debug.waitForDebugger();
if (prgDlg.isShowing())
prgDlg.dismiss();
}
}
}
行
View inflated = inflater.inflate(R.layout.activity_details, rootView);
は私にエラーを与える:私はこれは私が今持っているコードで、JohnBokerの以前の提案@続く
06-27 16:47:24.010:
ERROR/AndroidRuntime(8830): Caused by:android.view.ViewRoot$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.
doInBackgroundメソッドで手動で膨張させるのはどうですか? –
あなたのレイアウトファイルを見て興味深いでしょう、私が思うに最適化しようとするのが最適です。 エミュレータまたは携帯電話/タブレットで1.5秒かかりますか? – Marty
こんにちは、実際には、eeePadトランスフォーマーで約1.5秒です。 どうすれば手動で膨らませることができますか? ここに投稿するレイアウトはかなり長いですが、約10-12の線形レイアウトと1つの実際のフラグメント(今のところ)があります。 – frapontillo