嗨,有谁知道如何创建一个刷新按钮,当按下它时它会显示一个加载微调器,然后当它停止时会返回到该按钮?
这是我到目前为止所得到的
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//Check Preferences which sets UI
checkPreferences();
PostTask posttask;
posttask = new PostTask();
posttask.execute();
Button backbtn = (Button) findViewById(R.id.backbtn);
//Listening to button event
backbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent previousScreen = new Intent(getApplicationContext(), ChooseTeamActivity.class);
ChosenMethod = "null";
SharedPreferences preferences = getSharedPreferences("prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("ChosenMethod", ChosenMethod);
editor.commit();
previousScreen.putExtra("FullData", fulldata);
startActivity(previousScreen);
}
});
Button refresh = (Button) findViewById(R.id.refresh);
//Listening to button event
refresh.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
PostTask posttask;
posttask = new PostTask();
posttask.execute();
}
});
这是我希望它加载的功能
public class PostTask extends AsyncTask<Void, String, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
boolean result = false;
loadFixtures();
publishProgress("progress");
loadResultsFeed();
publishProgress("progress");
loadNewsFeed();
publishProgress("progress");
return result;
}
protected void onProgressUpdate(String... progress) {
StringBuilder str = new StringBuilder();
for (int i = 1; i < progress.length; i++) {
str.append(progress[i] + " ");
}
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
Log.v("BGThread", "begin fillin data");
FillData();
}
}