重新加载时Android旋转刷新按钮
大家好,有人知道如何创建一个刷新按钮,当按下它时会显示一个加载微调器,然后当它停止时会返回到该按钮吗 这是我到目前为止得到的重新加载时Android旋转刷新按钮,android,android-asynctask,refresh,Android,Android Asynctask,Refresh,大家好,有人知道如何创建一个刷新按钮,当按下它时会显示一个加载微调器,然后当它停止时会返回到该按钮吗 这是我到目前为止得到的 @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); //Check Preferences which sets UI ch
@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();
}
}
公共类PostTask扩展了AsyncTask{
@凌驾
受保护的布尔doInBackground(Void…params){
布尔结果=假;
装载装置();
出版进度(“进度”);
loadResultsFeed();
出版进度(“进度”);
loadNewsFeed();
出版进度(“进度”);
返回结果;
}
受保护的void onProgressUpdate(字符串…进度){
StringBuilder str=新的StringBuilder();
for(int i=1;i
在xml文件中创建
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_margin="10dip"
android:visibility="gone" >
</ProgressBar>
</RelativeLayout>
在你的OnPostExecute上
findViewById(R.id.refresh).setVisibility(View.VISIBLE);
findViewById(R.id.progress).setVisibility(View.GONE);
我也遇到了同样的问题,因此我为此创建了一个专用按钮: 包括如下按钮:
<br.com.simplepass.loading_button_lib.CircularProgressButton
android:id="@+id/btn_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/circular_border_shape"
app:spinning_bar_width="4dp" <!-- Optional -->
app:spinning_bar_color="#FFF" <!-- Optional -->
app:spinning_bar_padding="6dp" <!-- Optional -->
CircularProgressButton btn = (CircularProgressButton) findViewById(R.id.btn_id)
btn.startAnimation();
[do some async task. When it finishes]
//You can choose the color and the image after the loading is finished
btn.doneLoagingAnimation(fillColor, bitmap);
[or just revert de animation]
btn.revertAnimation();
CircularProgressButton btn = (CircularProgressButton) findViewById(R.id.btn_id)
btn.startAnimation();
[do some async task. When it finishes]
//You can choose the color and the image after the loading is finished
btn.doneLoagingAnimation(fillColor, bitmap);
[or just revert de animation]
btn.revertAnimation();