单击任何项目时都有Recyclerview,应该显示该项目的进度条,但是当我单击某个项目时,进度条显示在错误的位置
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
android:id="@+id/icon_container"
<RelativeLayout
android:id="@+id/icon_back"
android:fillEnabled="false">
<ImageView
...
android:src="@drawable/bg_circle" />
<ImageView
...
android:src="@drawable/ic_done_white_24dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/icon_front"
<ImageView
...
android:layout_height="@dimen/icon_width_height" />
<TextView
...
android:textSize="@dimen/icon_text" />
</RelativeLayout>
</RelativeLayout>
<TextView
...
android:textStyle="bold" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
这是我的课程:
@Override
public void onMessageRowClicked(int position) {
progressBar = recyclerView.findViewHolderForLayoutPosition(position).itemView.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
...
}
答案 0 :(得分:3)
替换此行:
progressBar = recyclerView.findViewHolderForLayoutPosition(position).itemView.findViewById(R.id.progressBar);
与此:
progressBar = recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.progressBar);