我在tabactivity和群组活动中遇到了后退按钮的问题。
现在我有一个4个标签,在标签中我还有一个活动。 后退按钮不适用于组活动和tabactivity。 我怎样才能做到这一点?
这是我的代码:
标签栏的
public class TabbarActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbar);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
Resources res = getResources();
intent = new Intent().setClass(this, StartActivity.class);
spec = tabHost.newTabSpec("ReweHaupt").setIndicator("ReweHaupt",
res.getDrawable(R.drawable.home))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, EinkauflisteActivity.class);
spec = tabHost.newTabSpec("EinkaufListe").setIndicator("EinkaufListe",res.getDrawable(R.drawable.einkaufliste))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this,FilialesuchenActivitiy.class);
spec = tabHost.newTabSpec("Filiarsuchen").setIndicator("Filiarsuchen",res.getDrawable(R.drawable.searchbuton))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this,NotizblockActivity.class);
spec = tabHost.newTabSpec("Notizblock").setIndicator("Notizblock",res.getDrawable(R.drawable.einkaufliste))
.setContent(intent);
tabHost.addTab(spec);
}
EinkauflisteACtivity.java
public class EinkauflisteActivity extends ActivityGroup {
// das brauchen wir für groupactivity
public static EinkauflisteActivity group;
private ArrayList<View> history;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.einkaufliste);
this.history = new ArrayList<View>();
group = this;
Button btnsenden = (Button) findViewById(R.id.btnsenden);
Button btnscaner = (Button) findViewById(R.id.btnscaner);
Button btnsuchen = (Button) findViewById(R.id.btnsuchen);
// wenn wir button clicken, rufen wir neu activity
btnsuchen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
View view = getLocalActivityManager().startActivity(
"Systemhaus",
new Intent(v.getContext(), SuchenActivitiy.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
replaceView(view);
}
});
}
public void replaceView(View v) {
history.add(v);
setContentView(v);
}
public void back() {
if (history.size() > 0) {
history.remove(history.size() - 1);
setContentView(history.get(history.size() - 1));
} else {
finish();
}
}
public void onBackPressed() {
back();
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
答案 0 :(得分:3)
后退按钮在这里不起作用
你必须在后退时覆盖
每个活动中onBackPressed()
并维护一个堆栈并弹出所需的活动