【发布时间】:2019-03-29 23:34:11
【问题描述】:
我正在为 recyclerview 中的单个项目使用 SwipeRevealLayout,并且还想在其上附加 OnClickListener。这是我的单个项目布局的xml文件:
<com.chauthai.swipereveallayout.SwipeRevealLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mode="normal"
app:dragEdge="left"
android:clickable="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:padding="8dp"
android:gravity="center_vertical"
android:clickable="false">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_archive"
android:clickable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Archive"
android:id="@+id/id_text_archive"
android:textSize="24sp"
android:textColor="@color/colorTextLight"
android:clickable="false"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:padding="8dp"
android:clickable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Chat Name"
android:textSize="24sp"
android:textColor="@android:color/black"
android:id="@+id/id_text_chat_head"
android:clickable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Chat Name"
android:textSize="18sp"
android:textColor="@color/colorChatroomSubTitle"
android:id="@+id/id_text_chat_sub_head"
android:clickable="false"/>
</LinearLayout>
</com.chauthai.swipereveallayout.SwipeRevealLayout>
这是我的查看器代码:
public class ChatHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
@BindView(R.id.id_text_chat_head)
TextView mChatHead;
@BindView(R.id.id_text_chat_sub_head)
TextView mChatSubHead;
@BindView(R.id.id_text_archive)
TextView mTextArchive;
private View mView;
private AnonymousReport mAnonymousReport;
public ChatHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(this);
}
public SwipeRevealLayout getSwipeRevealLayout() {
return ((SwipeRevealLayout) mView);
}
public void bindView(AnonymousReport report) {
mAnonymousReport = report;
mChatHead.setText(report.getSubject());
mChatSubHead.setText(report.getAnonTypeText(mContext));
mTextArchive.setText(isArchived ? "Unarchive" : "Archive");
}
@Override
public void onClick(View v) {
startActivity(AnonymousReportDetailsActivity.newIntent(mContext, mAnonymousReport));
}
}
我已经尝试附加 onActionEvent 并且可以正常工作,但我不需要让 OnClickListner 工作。 有人可以帮我解决这个问题吗?谢谢
【问题讨论】:
标签: java android android-recyclerview onclicklistener