2013-04-24 26 views
0

我想使用户点击布局时可见的列表视图。我已将setOnClickListener添加到布局。但是当我点击布局时,listview不可见。你能帮我解决这个问题吗?下面是我的代码:Listview visibilty

transparentListView = (ListView) findViewById(R.id.tarnsparent_list_view); 


LinearLayout lt = (LinearLayout)findViewById(R.id.layout); 

lt.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       System.out.println("On click listener"); 
       transparentListView.setVisibility(View.VISIBLE); 
       for (int j=0;j<sectionListItems.size();j++) 
       { 
        System.out.println("section " + sectionListItems.get(j).toString()); 
       } 
       ArrayAdapter<String> myarrayAdapter = new ArrayAdapter<String>(getApplicationContext(), 
       android.R.layout.simple_list_item_1, sectionListItems); 
       for(int k = 0;k<myarrayAdapter.getCount();k++) 
       { 
        System.out.println("Adapter " + myarrayAdapter.getItem(k)); 
       } 
       transparentListView.setAdapter(myarrayAdapter); 
      } 
     }); 

下面是我的XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:padding="10dip" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:clipToPadding="false"> 

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:clickable="true" 
    android:id="@+id/layout" 
    android:focusable="true"> 
    <TextView 
    android:id="@+id/sep" 

    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 

    android:text="seperator 0" 
    android:textColor="#104E8B" 
    android:paddingLeft="4dip" 
    android:visibility="visible"/> 


    </LinearLayout> 

    <com.example.dlist.Stacklist 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    </com.example.dlist.Stacklist> 


</TableLayout> 


<ListView 
    android:id="@+id/tarnsparent_list_view" 
    android:layout_width="150dip" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="80dp" 
    android:layout_gravity="top" 
    android:layout_marginTop="50dp" 

    android:visibility="gone"> 
</ListView> 
</LinearLayout> 

感谢

+0

发布您的Layoout xml也 – 2013-04-24 10:05:45

+0

您可以在Log中打印sectionListItems大小吗? – 2013-04-24 10:05:55

+0

是的,我能看到,在日志 – Vyshakh 2013-04-24 10:09:33

回答

3

ü给表格布局的高度match_parent。所以你无法看到它,因为它会占据整个屏幕。所以使它wrap_content或给它一些价值。

+0

谢谢,它为我工作。 – Vyshakh 2013-04-24 10:55:10

1

更改您的表布局样式这样

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_parent" >