Androidアプリケーションで砂時計をプログラムで表示するにはどうすればよいですか?
19741 次
2 に答える
45
あなたは使用することができますProgressDialog
:
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Thinking...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
上記のコードは、あなたの上に次のダイアログを表示しますActivity
:
代わりに(または追加で)、のタイトルバーに進行状況インジケーターを表示できますActivity
。
次のコードを使用して、メソッドの上部にある機能としてこれをリクエストする必要があります。onCreate()
Activity
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
次に、次のようにオンにします。
setProgressBarIndeterminateVisibility(true);
次のようにオフにします。
setProgressBarIndeterminateVisibility(false);
于 2010-01-26T15:11:52.920 に答える
3
AsyncTaskを使用してそれを行う簡単な例を次に示します。
public class MyActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
...
new MyLoadTask(this).execute(); //If you have parameters you can pass them inside execute method
}
private class MyLoadTask extends AsyncTask <Object,Void,String>{
private ProgressDialog dialog;
public MyLoadTask(MyActivity act) {
dialog = new ProgressDialog(act);
}
protected void onPreExecute() {
dialog.setMessage("Loading...");
dialog.show();
}
@Override
protected String doInBackground(Object... params) {
//Perform your task here....
//Return value ... you can return any Object, I used String in this case
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return(new String("test"));
}
@Override
protected void onPostExecute(String str) {
//Update your UI here.... Get value from doInBackground ....
if (dialog.isShowing()) {
dialog.dismiss();
}
}
}
于 2014-12-04T16:44:31.777 に答える