【问题标题】:Listview visibility列表视图可见性
【发布时间】:2013-04-17 19:57:09
【问题描述】:

我试图在用户单击布局时使列表视图可见。我已将 setOnClickListener 添加到布局中。但是当我单击布局时,列表视图不可见。你能帮我解决这个问题吗?以下是我的代码:

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>

【问题讨论】:

  • 也发布您的 Layout xml
  • 你能在 Log 中打印 sectionListItems 的大小吗?
  • 是的,我可以在日志中看到
  • @Hardik 这些是sectionListItem元素: section abe section abe1 section abe2 section abe3 section abe4 section abe5 section abe6 section abe7 大小为8
  • @user370305 嗨,我已经放了 View.OnClickListener 但仍然没有运气。

标签: android android-listview visibility onclicklistener


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    像这样改变你的表格布局样式

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-12
      • 2014-07-04
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多