0
在我的xml我有:如何显示/隐藏项目点击ListView ListItem中的RelativeLayout?
<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
被点击的项目保持隐藏状态,但其他一些随机项目变为可见。
你为什么使用onItemClickListener?这是ListView。改为创建onClickListener()。 – Enigma
是的,你是对的我在listvew中使用它,我道歉我没有提到。 – Sayyam
我不知道我明白这一点。发布你的整个代码。 – Enigma