本文介绍了使用tabhost通过扩展MapActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content">
        <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"  android:paddingTop="5dip">
            <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/main">
                <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1"/>
                <TextView android:id="@+id/empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="Loading"/>
            </LinearLayout>
            <RelativeLayout android:id="@+id/mainlayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
                <com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="0Ua9BENcUvNKEom7wvjrrtlCVIeJ9SNYAbLAkJA"/>
            </RelativeLayout>
        </FrameLayout>
    </TabWidget>
</TabHost>


public class TabbedListMapActivity extends MapActivity implements OnTabChangeListener {

        private static final String LIST_TAB_TAG = "List";
        private static final String MAP_TAB_TAG = "Map";

         private TabHost tabHost;

        private ListView listView;
        private MapView mapView;
        private  LocalActivityManager mLocalActivityManager ;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
           setContentView(R.layout.main);

            tabHost = (TabHost) findViewById(android.R.id.tabhost);
            tabHost.setup();
            tabHost.setup();
            // LayoutInflater.from(this).inflate(R.layout.maplv, tabHost.getTabContentView(), true);
            // setup must be called if you are not inflating the tabhost from XML

            tabHost.setOnTabChangedListener(this);

            // setup list view
            listView = (ListView) findViewById(R.id.list);
            listView.setEmptyView((TextView) findViewById(R.id.empty));

            // create some dummy coordinates to add to the list
            List<GeoPoint> pointsList = new ArrayList<GeoPoint>();
            pointsList.add(new GeoPoint((int)(32.864*1E6), (int)(-117.2353*1E6)));
            pointsList.add(new GeoPoint((int)(37.441*1E6), (int)(-122.1419*1E6)));
            listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, pointsList));

            // add an onclicklistener to see point on the map
            listView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView parent, View view, int position, long id) {
                    GeoPoint geoPoint = (GeoPoint) listView.getAdapter().getItem(position);
                    if(geoPoint != null) {
                        // have map view moved to this point
                        setMapZoomPoint(geoPoint, 12);
                        // programmatically switch tabs to the map view
                        tabHost.setCurrentTab(1);
                    }
                }
            });

            // setup map view
            mapView = (MapView) findViewById(R.id.mapview);
            mapView.setBuiltInZoomControls(true);


            mapView.postInvalidate();

            // add views to tab host
            tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG).setIndicator("List").setContent(R.id.list));
            tabHost.addTab(tabHost.newTabSpec(MAP_TAB_TAG).setIndicator("Map").setContent(R.id.mapview));

            //HACK to get the list view to show up first,
            // otherwise the mapview would be bleeding through and visible
            tabHost.setCurrentTab(1);
            tabHost.setCurrentTab(0);
        }

        /**
         * Instructs the map view to navigate to the point and zoom level specified.
         * @param geoPoint
         * @param zoomLevel
         */
        private void setMapZoomPoint(GeoPoint geoPoint, int zoomLevel) {
            mapView.getController().setCenter(geoPoint);
            mapView.getController().setZoom(zoomLevel);
            mapView.postInvalidate();
        }

        /**
         * From MapActivity, we ignore it for this demo
         */
        @Override
        protected boolean isRouteDisplayed() {
            return false;
        }

        /**
         * Implement logic here when a tab is selected
         */
        public void onTabChanged(String tabName) {
            if(tabName.equals(MAP_TAB_TAG)) {
                //do something on the map
            }
            else if(tabName.equals(LIST_TAB_TAG)) {
                //do something on the list
            }
        } } 

我得到类似 HTTP结果://i3.6。 CN / cvbnm / E1 / 71 / E9 / 19008bd7258eaf858be73dc6431b1f8b.jpg 。我想获得两个标签;你能帮助我吗?

I get a result similar to http://i3.6.cn/cvbnm/e1/71/e9/19008bd7258eaf858be73dc6431b1f8b.jpg.I want to get two tabs; could you help me?

推荐答案

您需要使用TabWidget:的或的以显示选项卡中的按钮,如果这就是你在找什么......

You need to use TabWidget : http://developer.android.com/reference/android/widget/TabWidget.html or http://developer.android.com/guide/tutorials/views/hello-tabwidget.html to show the buttons for the tabs if that's what you are looking for...

这篇关于使用tabhost通过扩展MapActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 09:12