如何在单击项目时在ListView ListItem中显示/隐藏RelativeLayout?

时间:2011-11-22 12:07:34

标签: android android-layout

在我的xml中我有:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:layout_width="wrap_content"
    android:background="#FFFFFF" android:id="@+id/listItemMainRelativeLayout">


    <RelativeLayout android:id="@+id/myFavourtiesPlaylistTextRelativeLayout"
        android:layout_centerVertical="true" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:layout_marginBottom="1dp"..... android:textColor="#000002"
            android:layout_width="wrap_content"></TextView>
        <TextView android:visibility="visible" .... android:id="@+id/myFavouritesPlaylistDescription"
            android:textColor="#000006"></TextView>
    </RelativeLayout>

    <RelativeLayout android:id="@+id/myFavourtiesPlaylistButtonRelativeLayout"
        android:layout_alignParentRight="true" android:layout_centerVertical="true"
        android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:focusableInTouchMode="false" android:visibility="gone">

        <ImageButton android:id="@+id/playListPlayButton"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:visibility="visible" android:background="@drawable/play_button"
            android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:focusable="false" android:focusableInTouchMode="false"/>
    </RelativeLayout>

</RelativeLayout> 

我的Java代码是:

public OnItemClickListener listOnItemClickListener = new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int position,
            long id) {

        if (previousSelectedListItem != -1) {

            Toast.makeText(getActivity(),
                    "Hidding Position:" + previousSelectedListItem,
                    Toast.LENGTH_LONG).show();

            RelativeLayout mainRelativeLayout = (RelativeLayout) v;

            RelativeLayout buttonsRelativeLayout = (RelativeLayout) mainRelativeLayout
                    .findViewById(R.id.myFavourtiesPlaylistButtonRelativeLayout);
            buttonsRelativeLayout.setVisibility(View.GONE);
        }

        Toast.makeText(getActivity(), "ShowingPosition:" + position,
                Toast.LENGTH_LONG).show();

        RelativeLayout mainRelativeLayout = (RelativeLayout) v;

        RelativeLayout buttonsRelativeLayout = (RelativeLayout) mainRelativeLayout
                .findViewById(R.id.myFavourtiesPlaylistButtonRelativeLayout);
        buttonsRelativeLayout.setVisibility(View.VISIBLE);

        previousSelectedListItem = position;

    }
};

预期行为:点击后,我想让项目中的myFavourtiesPlaylistButtonRelativeLayout可见。

正在发生的事情: myFavourtiesPlaylistButtonRelativeLayout点击的项目仍处于隐藏状态,但其他一些随机项目仍然可见。

1 个答案:

答案 0 :(得分:1)

我相信在ListView中有一个RelativeLayout是个问题。我今天6小时在一个相同的问题上浪费了。

ListView element not clickable

尝试阅读此帖子,它应该提供修复。

http://code.google.com/p/android/issues/detail?id=3414