如果你想顯示進度的提示對話框中列出的裝載前,再使用的AsyncTask了點。
例如爲:
private class LoadingTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute(){
super.onPreExecute();
progressDialog.show();
}
@Override
protected String doInBackground(String... str) {
String response = "";
// Call Web Service here and return response
response = API.getDealsByCategory(str[0], str[1]);
// e.g.: above is my WebService Function which returns response in string
return response;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
System.out.println("result is: "+result);
new Thread(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
}
}).start();
// SHOW THE ALERT DIALOG HERE.....
}
}
呼叫的AsyncTask如象下面這樣:
LoadingTask任務=新LoadingTask(); task.execute(「YOUR_PARAMETER」,「YOUR_PARAMETER」);
// ==============================
只要把下面的代碼中的後Excution AsyncTask,你會得到你想要的。
final CharSequence[] items = {"","50","100","150","200","250","300","350","400","450","500","550","600","650","700","750","800","850","900","1000"};
AlertDialog.Builder builder = new AlertDialog.Builder(getParent());
builder.setTitle("Select Country");
//builder.setI
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
//Toast.makeText(getApplicationContext(), con.get(item).getCountrName(), Toast.LENGTH_SHORT).show();
selectDistanceTV.setText(items[item]);
System.out.println("Item is: "+items[item]);
/*CONTRY_ID = con.get(item).getCountryId();
stateET.requestFocus();*/
}
});
AlertDialog alert = builder.create();
alert.show();
希望它能幫助你。
如果您需要關於如何使用的AsyncTask更多的幫助,然後看到這裏:Vogella
評論我要任何查詢。
享受編碼... :)
非常感謝:)它工作:)我想添加一個更新按鈕,可以更新列表。這怎麼可能?? – Mona
表示你想要列表中的按鈕? –
評論我的任何查詢和感謝接受答案。 –