[英]Android Disable any onTouch
我開發了一個Android應用,該應用通過HTTP請求與服務器進行通信。 有時,請求會花費更多時間,因此應用程序僅顯示黑屏,並在幾秒鍾后通過。 有時,黑屏會在幾秒鍾后出現,您可以一次又一次發送請求。
屏幕加載時是否有可能禁用onTouch事件或顯示圖層?
謝謝。
使用asyncTask
並在doInBackground()
方法中啟動您的httprequest,並且為了阻止用戶,只需顯示一個ProgressDialog
:
class YourRequestTask extends AsyncTask<Void, Void, JSONObject> {
ProgressDialog progress;
Context context;
public YourRequestTask(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(context, null,"Please wait...");
}
@Override
protected JSONObject doInBackground(Void... params) {
//do your work here for your http request
}
@Override
protected void onPostExecute(JSONObject result) {
progress.dismiss();
Log.i(TAG, "result is "+result.toString());
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.