Android 标签视图
我在选项卡视图中遇到问题。我必须显示选项卡视图许多导航。例如 。在第一个名为“销售”的选项卡中,它列出了所有销售路线。如果用户单击一条路线,则需要转到零售商列表,就像在第一个选项卡中一样。有许多页面(视图)可用。
从我看来,它仅在第一个视图中显示选项卡,这意味着当它加载选项卡时,它会向我显示带有选项卡视图的销售路线列表。当我单击销售路线时,它显示零售商但不出现选项卡视图。
这是我的代码: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:
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);
}
@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;
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.我们如何实现它。
所有子 Activity 都需要显示选项卡视图。
请帮助我如何调用其他 xml 以使用选项卡视图进行导航。
提前致谢。
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.
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>
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);
}
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);
}
}
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);
}
In here i have to show listActivity & TabActivity.How we can implement this.
All the child Activity need to show tab view.
Please help me how to call other xml for navigation with tab view.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我提供一个演示,希望它能帮助您....
首先声明一个像这样的
ActivityGroup
SalesActivityGroup.java
在此更改您的主机(mainActivity)(仅更改一个 TabSpec :firstTabSpec,我猜它与销售相关)就像这样...
之后,当您想在firstTab(salesTab)中启动新活动时,您只需要更改与该salesTab相关的ActivityGroup的视图,
如下所示(启动您的listRetailerActivity 以下方式)...
Ok i am providing a demo i hope it will help you ....
Firs of all declare one
ActivityGroup
like thisSalesActivityGroup.java
After this change your host(mainActivity)(Change only one TabSpec : firstTabSpec which is related to sales i guess) like this ...
Afterward when ever you want to start new Activity in firstTab(salesTab) you just need to change view of ActivityGroup related to that salesTab
like this (start your listRetailerActivity following way )...