当我点击选项卡应用程序关闭

时间:2011-12-14 07:55:12

标签: android xml

我创建了一个带有3个标签的应用程序,1)post,2)listview,3)mapview。当我第一次点击任何标签时它显示相应的内容。如果我第二次点击任何标签,像我点击列表视图然后如果我点击发布,如果尝试点击列表视图应用程序关闭再次点击。如果有人知道它请帮助我

我写的源代码是,

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class TabWidgetActivity extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost();  // The activity TabHost
TabHost.TabSpec spec;  // Resusable TabSpec for each tab
Intent intent;  // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, PostEvent.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("post").setIndicator("Post",
                      res.getDrawable(R.drawable.ic_tab_grey))
                  .setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, EventList.class);
spec = tabHost.newTabSpec("list").setIndicator("ListView",
res.getDrawable(R.drawable.ic_tab_grey))
                  .setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MapViewEvents.class);
spec = tabHost.newTabSpec("map").setIndicator("MapView",
               res.getDrawable(R.drawable.ic_tab_grey))
                  .setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}

1 个答案:

答案 0 :(得分:0)

现在再试一次。

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class TabWidgetActivity extends TabActivity {

TabHost tabHost;
TabHost.TabSpec spec;  // Resusable TabSpec for each tab
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
tabHost = getTabHost();  // The activity TabHost

Intent intent;  // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, PostEvent.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("post").setIndicator("Post",
                      res.getDrawable(R.drawable.ic_tab_grey))
                  .setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, EventList.class);
spec = tabHost.newTabSpec("list").setIndicator("ListView",
res.getDrawable(R.drawable.ic_tab_grey))
                  .setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MapViewEvents.class);
spec = tabHost.newTabSpec("map").setIndicator("MapView",
               res.getDrawable(R.drawable.ic_tab_grey))
                  .setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}