1

2つのSimpleAdaptersを使用して作成された2つのListView(下の画像を参照)を含むレイアウトがあります。QLocations ListViewの上部にあるListViewと、AllLocationsListViewの下部にあるListViewを呼び出しましょう。

AllLocationsListViewからすべての赤いTextView要素を非表示にします。TextViewsをAllLocationsリストビューからのみ分離し、QLocationsListViewからも分離する方法がわかりません。

だから、私の質問は、特定のListViewからすべてのTextView要素を非表示にするにはどうすればよいですか?

ここに画像の説明を入力してください

これが私のコードです:

ListViewの作成

    // 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>
4

2 に答える 2

1

最初に、リストビュー項目とデータの間に 1 対 1 のマッピングがないことを知っておいてください。多くのアイテムがある場合、リストをスクロールするとビューが再利用されます。

最初に、アダプタ内のすべてのアイテムの を更新して正しい値にします。データを更新したら。次に、データが変更されたことをアダプターに通知し、それ自体を再構築しますadapter.notifyDataSetChanged()。必要に応じてデータをキャッシュして、リストの再構築を高速化します。

ここで何が起こっているのかをよりよく理解するために、MVC (Model-View-Controller) を読んでください。

于 2013-01-27T23:12:44.743 に答える