我在Android上遇到了一个恼人的问题。
我有一个隐藏的FrameLayout
,在ImageView的顶部有一个“检查状态”。当用户点击该行时,它应该显示或隐藏,具体取决于实际状态。
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/layoutSearchGroupItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:focusableInTouchMode="false"
android:orientation="horizontal"
android:weightSum="1"
android:paddingLeft="@dimen/ulife_gutter"
android:paddingRight="@dimen/ulife_gutter"
android:paddingTop="@dimen/ulife_half_gutter"
android:paddingBottom="@dimen/ulife_half_gutter">
<FrameLayout
android:id="@+id/chatFeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/image_radius_transparent_gray"
android:orientation="vertical"
android:tag="chatFeed"
android:clipChildren="false"
android:clipToPadding="false">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/layoutSearchResultImage"
android:layout_width="@dimen/ulife_ic_size"
android:layout_height="@dimen/ulife_ic_size"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="@string/alt_activity_picture"
android:longClickable="false"
android:maxHeight="@dimen/ulife_max_height"
app:riv_corner_radius="@dimen/ulife_corner_avatar_radius"
android:scaleType="centerCrop"
android:src="@drawable/luiz_back" />
<FrameLayout
android:id="@+id/frameSelectedUser"
android:layout_width="wrap_content"
android:layout_height="@dimen/ulife_ic_tiny_size"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/ulife_13_gutter"
android:layout_marginRight="@dimen/ulife_13_gutter"
android:animationCache="false"
android:background="@drawable/border_radius_5_green"
android:clipChildren="false"
android:visibility="gone"
android:minWidth="@dimen/ulife_ic_tiny_size">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:autoText="false"
android:paddingLeft="@dimen/ulife_13_gutter"
android:paddingRight="@dimen/ulife_13_gutter"
android:singleLine="true"
android:tag="textChatFeedCount"
android:text="√"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="@dimen/ulife_paragraph_small_size" />
</FrameLayout>
</FrameLayout>
<LinearLayout
android:id="@+id/layoutSearchResultInfoContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_marginLeft="@dimen/ulife_gutter">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carlos Silva"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/gray"
android:textSize="@dimen/ulife_paragraph_size"
android:textStyle="bold|normal" />
<TextView
android:id="@+id/textInstitute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Instituto Chico Chavier"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/gray"
android:textSize="@dimen/ulife_paragraph_size"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
我的onItemClickListener:
listResultsPeopleContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SearchPeopleDetailAdapter searchPeopleDetailAdapter = (SearchPeopleDetailAdapter) listResultsPeopleContainer.getAdapter();
SearchUserReceiver user = searchPeopleDetailAdapter.getItem(position);
Boolean addUser = true;
for (SearchUserReceiver userReceiver : selectedUsers) {
Logger.e(user.type.toString() + " selectedUsers");
if (userReceiver.id == user.id) {
addUser = false;
}
}
if (addUser) {
((FrameLayout) view.findViewById(R.id.frameSelectedUser)).setVisibility(View.VISIBLE);
selectedUsers.add(user);
} else {
SearchUserReceiver userReceiverRemove = null;
((FrameLayout) view.findViewById(R.id.frameSelectedUser)).setVisibility(View.INVISIBLE);
for (SearchUserReceiver userReceiver : selectedUsers) {
if (userReceiver.id == user.id) {
userReceiverRemove = userReceiver;
}
}
if (userReceiverRemove != null) {
selectedUsers.remove(userReceiverRemove);
}
}
((SearchPeopleActivity) getActivity()).usersSelected = selectedUsers;
}
});
我知道Android回收查看过程,但我无法找到如何避免此问题。 以下是所选第一项的打印。
第二个打印是列表中的第11个项目,它没有点击,它已经过检查!
答案 0 :(得分:0)
您必须使用FrameLayout
方法重新设置getView()
可见性。