我在选项卡视图中有问题。我必须显示许多导航选项卡视图。例如。在第一个名为“Sales”的选项卡中,它列出了所有的销售路线。如果用户单击一个路线,它需要像WISE ITS GO一样在第一个选项卡中列出零售商。有许多页面(视图)可用。
从第一个视图中的my it-only-show选项卡,这意味着当它加载tab时,它显示了带有tab视图的销售路线列表。当我单击Sales Route时,它显示Retailer,但不显示选项卡视图。
这是我的代码:tabview.xml

   <?xml version="1.0" encoding="utf-8"?>

<TabHost android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost">
<LinearLayout android:id="@+id/LinearLayout01"
    android:orientation="vertical" android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <TabWidget android:id="@android:id/tabs"
        android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
    <FrameLayout android:id="@android:id/tabcontent"
        android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout>
</LinearLayout>

这是我的主要活动:
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabview);

    TabHost t = getTabHost();
    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

    TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
    TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
    TabSpec thirdTabSpec = tabHost.newTabSpec("tid1");
    /** TabSpec setIndicator() is used to set name for the tab. */
    /** TabSpec setContent() is used to set content for a particular tab. */
    firstTabSpec.setIndicator("Sales").setContent(new Intent(this,SalesRouteActivity.class));
    secondTabSpec.setIndicator("Admin").setContent(new Intent(this,SalesRoutesTab.class));
    thirdTabSpec.setIndicator("Setting").setContent(new Intent(this,SalesRoutesTab.class));

    /** Add tabSpec to the TabHost to display. */
    tabHost.addTab(firstTabSpec);
    tabHost.addTab(secondTabSpec);
    tabHost.addTab(thirdTabSpec);
}

这是我的销售活动;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sales_routes);
    ArrayList<Object> routeList = getWmRoute();
    ArrayList<String> routhPath = new ArrayList<String>();
    for(int i = 0; i<routeList.size();i++){
        routhPath.add(((WMRoute) routeList.get(i)).getDescription());
    }

    ArrayAdapter ad = new ArrayAdapter(this,android.R.layout.simple_list_item_single_choice,routhPath);
    setListAdapter(ad);
    final ListView list=getListView();
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setItemsCanFocus(true);
    list.setTextFilterEnabled(true);
    list.setItemChecked(positions,true);
    keyword = (String) list.getItemAtPosition(0);

}
   @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("OK");
    menu.add("Cancel");
    return super.onCreateOptionsMenu(menu);
  }

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case 0:
        Intent showContent = new Intent(getApplicationContext(),ListRetailerActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("RouteName", keyword);
        showContent.putExtras(bundle);
        startActivity(showContent);
        return true;
    case 1:
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

这是零售商零件清单零售商活动;
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.retailer_list);

    Bundle bundle = this.getIntent().getExtras();
    String routeName = bundle.getString("RouteName");
    setTitle(routeName + " - List Retailer ");

    ArrayList<Object> routeList = getWmRoute();
  //  ArrayList<String> routhPath = new ArrayList<String>();
    ArrayList<HashMap<String,String>> alist=new ArrayList<HashMap<String,String>>();

    for(int i = 0; i<routeList.size();i++){
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("RetailerCode", ((WMRoute) routeList.get(i)).getDescription());
        map.put("RetailerName", ((WMRoute) routeList.get(i)).getBusinessUnit());
        alist.add(map);
    }

    ListView list=getListView();
    sd = new SimpleAdapter(this,alist,R.layout.retalier_rows,new String[]{"RetailerCode","RetailerName"},new int[]{R.id.retailerCode,R.id.retailerName});
    list.setAdapter(sd);
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setSelected(true);
    list.setSelection(0);
    list.setTextFilterEnabled(true);
    list.setItemsCanFocus(true);
    list.setTextFilterEnabled(true);
    list.setItemChecked(positions,true);
    keyword = ((WMRoute) routeList.get(0)).getBusinessUnit();
    //keyword = (String) list.getItemAtPosition(0);


}

在这里我要展示listactivity和tabactivity,我们如何实现它。
所有子活动都需要显示选项卡视图。
请帮助我如何调用其他XML以使用选项卡视图进行导航。
提前谢谢。

最佳答案

好的,我正在提供一个演示我希望它能帮助你…
所有人中的第一个都声明一个ActivityGroup像这样SalesActivityGroup.java

public class SalesActivityGroup extends ActivityGroup {

                // Keep this in a static variable to make it accessible for all the nested activities, lets them manipulate the view
            public static SalesActivityGroup 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 = this;

                      // Start the root activity withing the group and get its view
                  View view = getLocalActivityManager().startActivity("Home", new
                                                    Intent(this,SalesRouteActivity.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() {
                if(history.size() > 0) {
                    history.remove(history.size()-1);
                    if(history.size() > 0) {
                         setContentView(history.get(history.size()-1));
                    }
                    else {
                        finish();
                    }
                }else {
                    finish();
                }
            }

           @Override
            public void onBackPressed() {
                SalesActivityGroup.group.back();
                return;
            }

  }

在此更改之后,您的主机(mainActivity)(只更改一个tabspec:firsttabspec,我猜它与销售有关)如下…
public class Host extends TabActivity {

    public static Button btnRed;
    public static TabHost tabHost;

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.host);

            tabHost = (TabHost)findViewById(android.R.id.tabhost);


            TabSpec salesTabSpec = tabHost.newTabSpec("tid1");

            Intent intent1 = new Intent(this, SalesActivityGroup.class);//SalesActivityGroup instead of SalesRouteActivity

            salesTabSpec.setContent(intent2);

             /* Add tabSpec to the TabHost to display. */
            tabHost.addTab(salesTabSpec);

        }
}

之后,当您想在firsttab(salestab)中启动新活动时,只需更改与该salestab相关的活动组的视图
像这样(从下面开始你的ListRetailerActivity)……
Intent intent = new Intent(SalesRouteActivity.this, ListRetailerActivity.class);

            // Create the view using FirstGroup's LocalActivityManager
            View view = SalesActivitytGroup.group.getLocalActivityManager()
            .startActivity("", intent
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                    .getDecorView();

            // Again, replace the view
            SalesActivityGroup.group.replaceView(view);

08-18 08:28