I m trying to show a loading icon to the user when the application makes a query to online Database. I ve tried using a AnimationDrawable (I gave up because there was no need of a custom icon), ProgressDialog and ProgressBar. The ProgressBar seems most appropriate, since I don t want a message, just a spinning icon. But I can not even make a ProgressBar appear on the screen, doesn t matter where I call it. I ve got the ProgressDialog appearing in screen, but it only appears after the server s response, and if I use dismiss() or cancel() it doesn t even appear at all.
我利用AsyncTasks或Threads取得了任何成功。
与此相对照的是,有一门JogarActative。 java, 当时计划列出各种备选办法。 用户功能和用户功能等一些参数:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.jogar_layout);
Intent in = getIntent();
String url = this.getString(R.string.urlSite);
ArrayList<HashMap<String, String>> respostaList = new ArrayList<HashMap<String, String>>();
String idt = in.getStringExtra(TAG_ID);
primeiraPergunta = in.getBooleanExtra(TAG_PRIMEIRAPERGUNTA, true);
TextView insertPergunta = (TextView) findViewById(R.id.insertPergunta);
ListView insertRespostas = (ListView) findViewById(R.id.listResposta);
SharedPreferences settings = getSharedPreferences("PREFS_LOGIN", MODE_PRIVATE);
Integer idUsuario = settings.getInt("idUsuario", 0);
String idUser = idUsuario.toString();
if (primeiraPergunta){
UserFunctions userFunction = new UserFunctions();
json = userFunction.getJogar(idt, idUser);
}else{
try {
json = new JSONArray(in.getStringExtra(TAG_JSON));
json = json.getJSONArray(2);
} catch (JSONException e) {
e.printStackTrace();
}
}
Below is the getJogar function in userFunctions: public JSONArray getJogar(String categoria, String usuarioId){ List params = new ArrayList();
params.add(new BasicNameValuePair("categoria", categoria));
params.add(new BasicNameValuePair("idUsuario", usuarioId));
JSONArray json = jsonParser.getJSONFromUrl(perguntaURL, params);
return json;
}
JSONParser.java is the class that makes the httpRequest: public JSONArray getJSONFromUrl(String url, List params) {
// Making HTTP request
try {
// defaultHttpClient
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
// json = EntityUtils.toString(httpEntity);
// HttpEntity httpEntity2 = httpEntity;
json = EntityUtils.toString(httpEntity);
// is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//then makes the JSON manipulation
只要JSONParser和用户功能是固定的,我就不使用他们内部的“进步”(Can t获得应用环境)。 所有服务器申请均在JSONParser提出。 java, 这就是为什么一夫先试图将“进步”/ProgressBar带走。
到达的“一号”最接近于在JogarActive公司使用这一代码(它显示进步运动,但经过服务器的反应)。 而且,如果我被解雇,甚至似乎就没有。
final ProgressDialog loader = new ProgressDialog(JogarActivity.this);
loader.show();
//...the if-else code i ve pasted above
loader.dismiss();
即便是使用OnUiThread,它还是用 t子做工! I m 没有选择......
感谢一切帮助。