Android的选项卡中查看 [英] Android Tab view

查看:184
本文介绍了Android的选项卡中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标签视图有问题。我必须表现出标签视图很多导航。例如 。在第一个标签叫销售,它列出route.If用户的所有销售点击一条路线就需要去零售商的名单像智者其在第一个选项卡中去。有很多页面(视图)可用。

I have issue in the tab view. I have to show tab view many navigation. For example . In the first tab called "Sales" , It list all sales route.If the user click one route it need to go list of retailer like wise its go in the first tab. There are many pages(views) available.

这是我的只显示选项卡中的第一种观点,这意味着当它加载标签,这表明我与标签查看销售路线的列表。当我点击的销售途径,它显示的零售商,但不会出现卡视图。

From my it only show tab in the first view , that means when it load tab, it showed me list of sales routes with tab view. When I click sales route, it display retailer but not appear tab view.

这是我的code:tabview.xml

This is my code : 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>

这是我mainActivity:

This is my mainActivity :

  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);
}

这是我的SalesRouteActivity;

This is my SalesRouteActivity;

  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);
    }
}

这是零售商的一部分ListRetailerActivity;

This is retailer part ListRetailerActivity;

   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.How我们可以实现这一点。

In here i have to show listActivity & TabActivity.How we can implement this.

所有的子活动需要显示选项卡视图。

All the child Activity need to show tab view.

请帮我如何调用其他的XML导航与标签视图。

Please help me how to call other xml for navigation with tab view.

在此先感谢。

推荐答案

好吧,我提供了一个演示中,我希望它会帮助你......

Ok i am providing a demo i hope it will help you ....

所有的杉杉定义一个的ActivityGroup 这样的 SalesActivityGroup.java

Firs of all declare one ActivityGroup like this 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这是关系到销售我猜)这样的...

After this change your host(mainActivity)(Change only one TabSpec : firstTabSpec which is related to sales i guess) like this ...

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)新的活动,你只需要改变看法的ActivityGroup有关的salesTab

Afterward when ever you want to start new Activity in firstTab(salesTab) you just need to change view of ActivityGroup related to that salesTab

这样的(启动listRetailerActivity以下方式)...

like this (start your listRetailerActivity following way )...

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);

这篇关于Android的选项卡中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆