2013-04-24 10 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" >