0

アクティビティが読み込まれるまでに時間がかかるので、このアクティビティの開始をクリックすると、( loading..... ) のような読み込みメッセージが表示されます。

これがこのアクティビティを開始したボタンです

    start.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Intent intent = new Intent(test.this, MainActivity.class);
            startActivity(intent);

        }
    });

MainActivity が読み込まれるまで、この読み込みメッセージを表示するには、ここにどのようなコードを記述すればよいでしょうか?

4

2 に答える 2

0

クリックすると読み込みに時間がかかるアクティビティ B が表示されるアクティビティ A がある場合、最も一般的な方法は次のとおりです。

  • アクティビティ B のレイアウト ビューにプログレス バーがあり、アクティビティ B の onCreate で表示できるようにします。

  • 長時間実行されるすべての操作は、asyncTask またはバックグラウンドで実行される Service に配置されます

  • 長時間実行されている操作が終了したら、可視性を View.GONE に設定してプログレス バーを更新します。

私はあなたにコードを書きたいと思いますが、私はあなたのコードを持っていないので、私ができる最善の方法はあなたの問題をステップに分割することだと思います.

于 2013-11-13T14:25:46.870 に答える
0

daneejela provided a solution but I do think that the reason for you long startup of your MainActivity is the real problem and should get fixed.

Activities will take long to startup when you do too much block method calls or such things in the MainThread. Try to do those things in a background Thread (you can use AsyncTask). This will result in an immediate Activity startup. While your AsyncTask is working, you can show a little ProgressDialog or better, show somewhere in your Activity a ProgressBar which is not blocking the user from doing any kind of action.

You should definitly understand Android's Main- and BackgroundThreading. There are also great tutorials for Dialogs. You should also check out the Android Design Guidlines.

于 2013-11-13T14:30:00.110 に答える