Android Tab Views - could not create tab content because could not find view with id

前端 未结 3 1106
粉色の甜心
粉色の甜心 2021-01-20 13:27

I am trying to create a tab view with will switch to a different content view by Id. Here is my tab activity:

public class TabViews extends TabA         


        
3条回答
  •  执念已碎
    2021-01-20 14:31

    you need add tabwidget in the xml.... Checkout, this is how to use tab widget :

    tabscroll.xml

    
        
            
                
            
            
        
    
    
    
        public class Tabs5 extends TabActivity implements TabHost.TabContentFactory {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.tabs_scroll);
    
            final TabHost tabHost = getTabHost();
    
            for (int i=1; i <= 30; i++) {
                String name = "Tab " + i;
                tabHost.addTab(tabHost.newTabSpec(name)
                        .setIndicator(name)
                        .setContent(this));
            }
        }
    
        /** {@inheritDoc} */
        public View createTabContent(String tag) {
            final TextView tv = new TextView(this);
            tv.setText("Content for tab with tag " + tag);
            return tv;
        }
    }
    

    Courtesy : http://developer.android.com/resources/samples/ApiDemos/res/layout/tabs_scroll.html AND http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Tabs5.html

提交回复
热议问题