从我在第一个视图中的仅显示选项卡,这意味着当它加载选项卡时,它显示了带有选项卡视图的销售路线列表.当我点击销售路线时,它会显示零售商,但不显示标签视图.
这是我的代码: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);}
这是我的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); }@OverrIDepublic 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;
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我们可以实现这个.
所有子Activity都需要显示选项卡视图.
请帮我如何使用选项卡视图调用其他xml进行导航.
提前致谢.
解决方法 好的我正在提供演示,我希望它能帮到你……Firs of all声明一个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相关的ActivityGroup视图
像这样(按照下面的方式开始你的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);总结
以上是内存溢出为你收集整理的Android标签视图全部内容,希望文章能够帮你解决Android标签视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)