当用户单击布局时,我试图使列表视图可见。我已将 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>