我不明白为什么onclick
没有处理图片。我尝试添加clickable
和focusable
,但没有运气。
我的Xml有图像视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:emojicon="http://schemas.android.com/apk/res-auto">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:id="@+id/messengerImageView"
android:src="@drawable/ic_account_circle_black_36dp"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="60dp">
<FrameLayout
android:id="@+id/incoming_layout_bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:background="@drawable/balloon_incoming_normal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold|italic"
android:text="Receiver"
android:textSize="16dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="10dp"
android:paddingBottom="12dp"
android:layout_marginLeft="6dp"
android:layout_above="@+id/messageTextView"
android:id="@+id/messengerTextView"
android:layout_weight="0"/>
<TextView
android:id="@+id/message_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="5dp"
android:text="11:15 PM"
android:layout_marginLeft="6dp"
style="@style/chat_timings"
android:layout_gravity="bottom|right"/>
<ImageView
android:id="@+id/image"
android:layout_width="150dp"
android:layout_height="160dp"
android:src="@drawable/ic_account_circle_black_36dp"
android:contentDescription="send_photo"
android:visibility="gone"
android:clickable="true"
android:focusable="true"
android:layout_marginTop="23dp"
android:layout_marginBottom="18dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_gravity="center"
android:scaleType="fitXY"/>
<ImageView
android:layout_width="150dp"
android:layout_height="120dp"
android:id="@+id/videoview"
android:contentDescription="send_video"
android:src="@drawable/videoiconcrop"
android:layout_marginTop="20dp"
android:layout_marginBottom="18dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_gravity="center"
android:visibility="gone"
/>
<hani.momanii.supernova_emoji_library.Helper.EmojiconTextView
android:id="@+id/messageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="50dp"
android:autoLink="web"
android:text="Rahul Agrawal is a good boy but he does not know what he wants."
style="@style/chat_text_message_style"
emojicon:emojiconSize="30sp"/>
<ImageView
android:id="@+id/notacceptmedia"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="bottom|left"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:clickable="true"
android:elevation="3dp"
android:focusable="true"
android:scaleType="fitXY"
android:src="@drawable/notacceptmedia" />
<ImageView
android:id="@+id/acceptmedia"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_marginRight="50dp"
android:layout_marginTop="50dp"
android:clickable="true"
android:elevation="3dp"
android:focusable="true"
android:scaleType="fitXY"
android:src="@drawable/common_google_signin_btn_icon_dark" />
</FrameLayout>
</RelativeLayout>
</LinearLayout>
我的观点持有人:
public static class MessageViewHolder extends RecyclerView.ViewHolder {
public EmojiconTextView messageTextView;
public TextView messengerTextView;
public CircleImageView messengerImageView;
public ImageView sendimage;
public ImageView videoview;
public TextView messageTime;
public ImageView acceptmedia;
public ImageView notacceptmedia;
public MessageViewHolder(View v) {
super(v);
messageTextView = (EmojiconTextView) itemView.findViewById(R.id.messageTextView);
messengerTextView = (TextView) itemView.findViewById(R.id.messengerTextView);
messengerImageView = (CircleImageView) itemView.findViewById(R.id.messengerImageView);
sendimage = (ImageView) itemView.findViewById(R.id.image);
videoview = (ImageView) itemView.findViewById(R.id.videoview);
messageTime = (TextView)itemView.findViewById(R.id.message_time);
acceptmedia =(ImageView) itemView.findViewById(R.id.acceptmedia);
notacceptmedia = (ImageView) itemView.findViewById(R.id.notacceptmedia);
}
}
在imageView上实现onclick的代码:
viewHolder.acceptmedia.setClickable(true);
//viewHolder.acceptmedia.setFocusable(true);
viewHolder.acceptmedia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(GroupChatScreen.this, "Accept", Toast.LENGTH_SHORT).show();
Log.e("test","Accept");
}
});
viewHolder.notacceptmedia.setClickable(true);
//viewHolder.notacceptmedia.setFocusable(true);
viewHolder.notacceptmedia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(GroupChatScreen.this, "Decline", Toast.LENGTH_SHORT).show();
Log.e("test","Decline");
}
});
答案 0 :(得分:0)
您可以使用图像按钮代替图像视图。 希望这能解决你的问题。