2011-04-03 90 views
0

嗨请帮忙 其实我试图使列表视图为不可见 但它同时显示listview和gridview,请帮助解决它。 这里是代码。创建视图

public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.main); 
     Gallery gallery = (Gallery) findViewById(R.id.gallery1); 
    lst=(ListView)findViewById(R.id.list); 
    lst.setVisibility(View.INVISIBLE); 
    // ViewManager hi=(ViewManager)getBaseContext().getSystemService(WINDOW_SERVICE); 


     gallery.setAdapter(new ImageAdapter(this));   
     final GridView gridView = (GridView) findViewById(R.id.gridview); 

     mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     data = new Vector<RowData>(); 
     for(int i=0;i<title.length;i++){ 
     try { 
      rd = new RowData(i,title[i],detail[i]); 
      } catch (ParseException e) { 
       e.printStackTrace(); 
      } 
      data.add(rd); 
      lst.setAdapter(new CustomAdapter(this, R.layout.list,R.id.title,data)); 
     } 

     gridView.setAdapter(new ImageAd(this)); 

     final TabHost tabs=(TabHost)findViewById(R.id.tabhost); 


     tabs.setup(); 

     final TabHost.TabSpec spec=tabs.newTabSpec("buttontab"); 
     final TabHost.TabSpec spec1=tabs.newTabSpec("btn"); 
     spec.setContent(R.id.list); 
     lst.setVisibility(View.INVISIBLE); 
     spec1.setContent(R.id.buttontab); 
     spec.setIndicator("tab1"); 

     spec1.setIndicator("tab1"); 
     tabs.addTab(spec); 
     tabs.setCurrentTab(0); 
     tabs.getTabWidget().getChildAt(0).setLayoutParams(new 
       LinearLayout.LayoutParams(30,30)); 
spec.setIndicator("tab2"); 
     tabs.addTab(spec); 
     tabs.getTabWidget().getChildAt(1).setLayoutParams(new 
       LinearLayout.LayoutParams(30,30)); 
     tabs.setOnTabChangedListener(new OnTabChangeListener(){ 
      @Override 
      public void onTabChanged(String tabId) { 
       if(tabId=="buttontab") 

,这里是xml文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="50px" 
    android:orientation="horizontal"> 
    <Button 
    android:id="@+id/login" 
    android:layout_width="80px" 
    android:layout_height="wrap_content" 
    android:text="Login" 
    /> 
    <TextView 
    android:paddingLeft="80px" 
    android:id="@+id/search" 
    android:layout_width="40px" 
    android:text="Search" 
    android:layout_height="wrap_content" 

    /> 
    <EditText 

    android:layout_width="100px" 
    android:layout_height="wrap_content" 
    /> 
    </LinearLayout> 
    <Gallery 
     android:id="@+id/gallery1" 
     android:layout_width="fill_parent" 
     android:layout_height="50px" /> 

    <TabHost android:id="@+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="62px"> 
      <ListView android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="200px" /> 
      <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      > 


     <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="fill_parent" 
    android:layout_height="200px" 
    android:numColumns="4" 
    android:verticalSpacing="5px" 
    android:horizontalSpacing="5px" 
    android:columnWidth="60dp" 
    android:stretchMode="columnWidth" 
    android:gravity="center" 
/>  
<LinearLayout 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
> 
<Button 
android:id="@+id/buttontab" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/icon"/> 
<ImageButton 
android:id="@+id/hello1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/icon"/> 

<ImageButton 
android:id="@+id/hello3" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/icon"/> 
<ImageButton 
android:id="@+id/hello4" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/icon"/> 
<ImageView 
android:id="@+id/hello5" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/icon"/> 

</LinearLayout> 
      </LinearLayout>> 
     </FrameLayout> 
    </TabHost> 
</LinearLayout> 

,请帮助,使列表视图作为invisiblei知道它的一个很小的错误,但未能解决错误

回答

0

尝试View.GONE而不是查看.INVISIBLE

既然你在的onCreate这样做,你能做到这一点在你的XML:

<ListView 
    android:id="@+id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="200px" 
    android:visibility="gone" 
/>