调用类,使用扩展的AppCompatActivity在类中扩展TabActivity

时间:2016-05-01 20:50:38

标签: java android xml

我希望只在类RequestsAdd中调用TabHost,但结果对象为null。

代码在这里:

Class RequestsAdd

public class RequestsAdd extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu_requests_add);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_requests_add);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout_requests);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}..........

类NavigationFragmentMenu

public class NavigationFragmentMenu extends TabActivity {

//@BindView(android.R.id.tabhost)
TabHost tabHost;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //tabHost.setup();
    tabHost = getTabHost();

    View view = LayoutInflater.from(this).inflate(R.layout.content_requests_add_eat, null);
    tabHost = ButterKnife.findById(view, android.R.id.tabhost);

    //Creating tab menu.
    TabHost.TabSpec TabMenu1 = tabHost.newTabSpec("CARDÁPIO");
    TabHost.TabSpec TabMenu2 = tabHost.newTabSpec("ENTREGA");

    //Setting up tab 1 name.
    TabMenu1.setIndicator("Tab1");
    //Set tab 1 activity to tab 1 menu.
    TabMenu1.setContent(new Intent(this,MenuFood.class));

    //Setting up tab 2 name.
    TabMenu2.setIndicator("Tab2");
    //Set tab 3 activity to tab 1 menu.
    TabMenu2.setContent(new Intent(this,MenuDelivery.class));

    //Adding tab1, tab2, tab3 to tabhost view.

    tabHost.addTab(TabMenu1);
    tabHost.addTab(TabMenu2);...........

布局: menu_requests_add.xml调用包含app_bar_requests_add.xml

app_bar_requests_add.xml调用包含content_requests_add_eat(android:id =" @ + id / content_requests_Layout")

content_requests_add_eat包含带有id tabhost的TabHost,OBJECT WANTED。

感谢帮助!

0 个答案:

没有答案