我使用回收视图,并且每行都有textview和image按钮。 在绑定我添加到图像按钮点击侦听器,但当我尝试点击图像按钮时,它点击行,只有当我长时间点击图像按钮时作出反应。将回收视图行中的点击侦听器添加到图像按钮
有什么建议吗?
@Override
public void onBindViewHolder(final FolderViewHolder holder, final int position) {
if (isFolder(position)) {
holder.folderName.setText(folders.get(position));
}else{
ImageButton edit = (ImageButton) holder.view.findViewById(R.id.browser_bookmark_row_edit);
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println(" ######### EDIT CLICKED");
mListener.switchToEditBookmarkFragmentFolderAdapter(bookmarks.get(position - folders.size()));
}
});
holder.folderName.setText(bookmarks.get(position - folders.size()).getTitle());
}
}
public class FolderViewHolder extends RecyclerView.ViewHolder {
MuseoSansTextView folderName;
View view;
public FolderViewHolder(View itemView, MuseoSansTextView museoSansTextView) {
super(itemView);
view = itemView;
folderName = museoSansTextView; //(MuseoSansTextView) itemView.findViewById(R.id.browser_bookmark_folder_name);
}
}
<android.support.v7.widget.CardView
android:id="@+id/card_view_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
card_view:cardBackgroundColor="@color/transparent"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardUseCompatPadding="false"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_horizontal_margin">
<com.osnewhorizon.pommmanager.ui.MuseoSansTextView
android:id="@+id/browser_bookmark_row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/browser_bookmark_row_edit"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:singleLine="true"
android:textColor="@color/white"
android:text="test"
android:textSize="@dimen/contact_row_title_height" />
<ImageButton
android:id="@+id/browser_bookmark_row_edit"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="5dp"
android:src="@drawable/edit"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
提供了FolderViewHolder类的实现。 – waleedsarwar86
也提供了xml文件的行项目。 – waleedsarwar86
添加了该行的xml – nahum