我有一个包含两个 ListView 的布局(见下图),它们都是使用两个 SimpleAdapter 创建的;让我们将 QLocations ListView 顶部的 ListView 称为 AllLocations ListView 底部的 ListView。
我想从我的 AllLocations ListView 中隐藏所有红色的 TextView 元素。我无法弄清楚如何仅将 TextViews 与 AllLocations ListView 隔离,而不是与 QLocations ListView 隔离。
所以,我的问题是,如何隐藏特定 ListView 中的所有 TextView 元素?
这是我的代码:
创建列表视图
// Getting qListView: List View for locations with Qs
qLV = (ListView) activity.findViewById(R.id.qListView);
// list adapter
ListAdapter qAdapter = new SimpleAdapter(activity, qListItems,
R.layout.google_places_item,
new String[] { KEY_REFERENCE, KEY_NAME}, new int[] {
R.id.reference, R.id.name });
// Adding data into listview
qLV.setAdapter(qAdapter);
// Getting allListView: List View for locations without Qs
allLV = (ListView) activity.findViewById(R.id.allListView);
// list adapter
ListAdapter allAdapter = new SimpleAdapter(activity, placesListItems,
R.layout.google_places_item,
new String[] { KEY_REFERENCE, KEY_NAME}, new int[] {
R.id.reference, R.id.name });
// Adding data into listview
allLV.setAdapter(allAdapter);
google_places_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/reference"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<!-- Row for each location -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/qLocationRow"
android:orientation="horizontal"
>
<!-- Q Name -->
<TextView android:id="@+id/name"
style="@style/qName"
/>
<!-- Q WaitTime -->
<TextView android:id="@+id/qName.qWaitTime"
style="@style/qName.qWaitTime"
android:text="14"
/>
</LinearLayout>
</LinearLayout>
活动布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/fullWidth">
<!-- Label for List View of QLocations -->
<TextView
android:id="@+id/qListLabel"
style="@style/widthMargins.Label"
android:text="@string/qListLabel" />
<!-- Horizontal Rule -->
<View
android:id="@+id/horizontalRule1"
style="@style/widthMargins.horizontalRule"
android:layout_below="@+id/qListLabel"
/>
<!-- Linear Layout containing progress bar + text description -->
<LinearLayout
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/lin_progressBar"
android:visibility="visible"
android:layout_centerHorizontal="true"
android:layout_below="@id/horizontalRule1"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ProgressBar
android:id="@+id/loadPlacesProgress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/loadPlacesText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:text="Loading..."
android:gravity="center_vertical"
android:textSize="15sp"
/>
</LinearLayout>
<!-- ListView for Q Locations -->
<ListView
android:id="@+id/qListView"
style="@style/widthMargins"
android:layout_height="140dp"
android:layout_below="@+id/horizontalRule1" />
<!-- Label for List View of All Locations -->
<TextView
android:id="@+id/allListLabel"
style="@style/widthMargins.Label"
android:layout_below="@+id/qListView"
android:text="@string/allListLabel" />
<!-- Horizontal Rule -->
<View
android:id="@+id/horizontalRule2"
style="@style/widthMargins.horizontalRule"
android:layout_below="@+id/allListLabel"
/>
<!-- Linear Layout containing progress bar + text description -->
<LinearLayout
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/lin_progressBar2"
android:visibility="visible"
android:layout_centerHorizontal="true"
android:layout_below="@id/horizontalRule2"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ProgressBar
android:id="@+id/loadPlacesProgress2"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/loadPlacesText2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:text="Loading..."
android:gravity="center_vertical"
android:textSize="15sp"
/>
</LinearLayout>
<!-- ListView for All Locations -->
<ListView
android:id="@+id/allListView"
style="@style/widthMargins"
android:layout_height="140dp"
android:layout_below="@+id/horizontalRule2"
/>
<!-- Show on Map button -->
<Button android:id="@+id/btn_show_map"
style="@style/fullWidth"
android:layout_centerHorizontal="true"
android:text="Map"
android:padding="20dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dip"/>
</RelativeLayout>