如何解决从super viewGroup android获取被点击的子视图
我正在使用chatsdk,在chatsdk中,有一个activity_chat.xml就是这样。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/viewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<sdk.chat.ui.appbar.ChatActionBar
android:id="@+id/chatActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<sdk.chat.ui.views.ChatView
android:id="@+id/chatView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/messageInputLinearLayout"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout
android:id="@+id/messageInputLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"
app:layout_behavior="sdk.chat.ui.appbar.TextInputBehavior">
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/_1sdp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="?chatViewDividerColor" />
<sdk.chat.ui.views.ReplyView
android:id="@+id/replyView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.stfalcon.chatkit.messages.MessageInput
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?chatViewMessageInputBackgroundColor"
app:showAttachmentButton="true" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
此类基本上将所有消息加载到ChatView中,这是一种方法,如果单击的视图包含音频类型的消息,则该方法将接收onClick事件。
public static void onClick(Activity activity,View view,String url,long id) {
BaseActivity.hideKeyboard(activity);
if (!url.isEmpty()) {
if (lastPlayingItemId != id || lastPlayingItemId == 0) {
if (lastPlayingItemId != 0) audioPlayer.stop();
imageViewState = null;
lastPlayingItemId = id;
imageViewState = view.findViewById(R.id.image_view_icon);
audioPlayer = new AudioPlayer(url,playerEventListener);
}
if (!audioPlayer.isPlaying()) audioPlayer.play();
else audioPlayer.stop();
}
}
在这种方法中,我要在onclick中获得“活动”,“视图”和“消息ID”,我想根据媒体播放器的状态显示播放或暂停图标。但是,每当我单击任何音频消息时,它始终会更改最新音频消息的图标,但它不会更改单击视图的图标,但是我始终会收到正确的ID和URL。因此,当我尝试评估View对象时,就像这样
据我了解,我正在获得根目录布局,现在我必须从messageList中找到被单击的项目,我已经尝试了足够的时间并进行了研究,但找不到解决方案。请提前帮助谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。