我是Android新手,任何人都可以告诉我如何在按下后退按钮时刷新活动。我想刷新视图,使标签不会消失。我发布了一个标签组代码。
public class ReviewTabGroup extends ActivityGroup {
// Keep this in a static variable to make it accessible for all the nested activities, lets them manipulate the view
public static ReviewTabGroup group;
// Need to keep track of the history if you want the back-button to work properly, don't use this if your activities requires a lot of memory.
private ArrayList<View> history;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.history = new ArrayList<View>();
group = ReviewTabGroup.this;
// Start the root activity withing the group and get its view
View view = getLocalActivityManager().startActivity("com.example.application.PeopleTab", new Intent(this,ReviewTab.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
// Replace the view of this ActivityGroup
replaceView(view);
}
public void replaceView(View v) {
// Adds the old one to history
history.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
public void back() {
System.out.println(history.size());
if(history.size() > 1) {
history.remove(history.size()-1);
setContentView(history.get(history.size()-1));
}else {
finish();
}
}
public void onBackPressed() {
ReviewTabGroup.group.back();
return;
}
}