Android 根据上一活动传递的信息设置每个tabhost的布局

Android 根据上一活动传递的信息设置每个tabhost的布局,android,android-layout,android-tabhost,textview,Android,Android Layout,Android Tabhost,Textview,我在设置选项卡式布局时遇到一些问题。我的目标是获取从上一个活动传递的一些信息,在本例中为“siteName”,并在onCreate期间将这些信息设置为我的一个选项卡中的文本字段 目前我遇到了nullPointer异常,只能在整体布局中设置值,在本例中是“位置选项卡菜单”,而不是在单个选项卡中 我到处找了几个小时,但找不到答案。我的代码如下: public class LocationTabbedMenu extends TabActivity { TextView title; /** Cal

我在设置选项卡式布局时遇到一些问题。我的目标是获取从上一个活动传递的一些信息,在本例中为“siteName”,并在onCreate期间将这些信息设置为我的一个选项卡中的文本字段

目前我遇到了nullPointer异常,只能在整体布局中设置值,在本例中是“位置选项卡菜单”,而不是在单个选项卡中

我到处找了几个小时,但找不到答案。我的代码如下:

public class LocationTabbedMenu extends TabActivity {
TextView title;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.location_tabbed_menu);



    //Get passed information
    Intent i = getIntent();
    String siteName = i.getStringExtra("name");



    TabHost tabHost = getTabHost();

    // Tab for Photos
    TabSpec infospec = tabHost.newTabSpec("Info");
    // setting Title and Icon for the Tab
    infospec.setIndicator("Info", getResources().getDrawable(R.drawable.location_tabbed_menu_info_icon));
    Intent infoIntent = new Intent(this, LocationTabbedMenuInfo.class);

    TextView title = (TextView) findViewById(R.id.textTest);
    title.setText(siteName);

    infospec.setContent(infoIntent);

    // Tab for Songs
    TabSpec foodspec = tabHost.newTabSpec("Food");
    foodspec.setIndicator("Songs", getResources().getDrawable(R.drawable.location_tabbed_menu_food_icon));
    Intent songsIntent = new Intent(this, LocationTabbedMenuFood.class);
    foodspec.setContent(songsIntent);

    // Tab for Videos
    TabSpec tipsspec = tabHost.newTabSpec("Tips");
    tipsspec.setIndicator("Videos", getResources().getDrawable(R.drawable.location_tabbed_menu_tips_icon));
    Intent videosIntent = new Intent(this, LocationTabbedMenuTips.class);
    tipsspec.setContent(videosIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(infospec); 
    tabHost.addTab(foodspec); 
    tabHost.addTab(tipsspec); 
}
}
请注意,值“testText”是单个选项卡中textview的id


任何帮助都将不胜感激。谢谢。

我怀疑最初的布局可能有问题。[请记住,“tabhost”、“tabs”和“tabcontent”的名称必须分别用于tabhost、TabWidget和FrameLayout。]另一种可能是引用的活动不存在或未在清单中引用。此外,我没有看到对“onTabChangeListener”的引用。这就是你第一眼看到标签标识符的地方:信息、食物或提示