Android OnClickListener未使用Custome适配器为ListView中的图像按钮触发
我花了太多时间寻找解决方案,尝试了不同的方法,但却找不到哪里出了问题 我正在开发一个应用程序,其中我有一个Android OnClickListener未使用Custome适配器为ListView中的图像按钮触发,android,listview,imagebutton,Android,Listview,Imagebutton,我花了太多时间寻找解决方案,尝试了不同的方法,但却找不到哪里出了问题 我正在开发一个应用程序,其中我有一个ImageButton作为listView的子元素(我使用自定义适配器完成了这项工作)。在执行ImageButton的OnClick时,不会发生任何事情 我的片段_tweets.xml如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="
ImageButton
作为listView
的子元素(我使用自定义适配器完成了这项工作)。在执行ImageButton
的OnClick
时,不会发生任何事情
我的片段_tweets.xml如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lvTweets" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
item_tweet.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:descendantFocusability="blocksDescendants"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
>
<ImageButton
android:layout_width="@dimen/profile_image_view_length"
android:layout_height="@dimen/profile_image_view_length"
android:background="@android:color/transparent"
android:id="@+id/ivProfilePicture"
android:scaleType="centerCrop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvUserName"
android:textColor="@color/black"
android:layout_alignTop="@+id/ivProfilePicture"
android:layout_toRightOf="@+id/ivProfilePicture"
android:layout_marginBottom="@dimen/margin_10dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textIsSelectable="false"/>
<com.codepath.apps.twitterclient.helpers.LinkifiedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvBody"
android:textColor="@color/black"
android:layout_toRightOf="@+id/ivProfilePicture"
android:autoLink="all"
android:layout_marginTop="@dimen/margin_30dp"
android:layout_marginBottom="@dimen/margin_10dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:textIsSelectable="false"/>
/>
<ImageView
android:layout_width="@dimen/margin_10dp"
android:layout_height="@dimen/margin_10dp"
android:id="@+id/ivClock"
android:layout_toLeftOf="@+id/tvTimeofPost"
android:src="@mipmap/ic_clock"
android:layout_marginTop="@dimen/margin_15dp"
android:layout_marginBottom="@dimen/margin_10dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvTimeofPost"
android:textColor="@color/gray"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="@dimen/margin_10dp"
android:layout_marginRight="@dimen/margin_5dp"
android:layout_marginLeft="@dimen/margin_5dp"
android:layout_marginBottom="@dimen/margin_10dp"
android:textIsSelectable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ivPostImage"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_below="@+id/tvBody"
android:layout_alignLeft="@+id/tvBody"
android:layout_alignStart="@+id/tvBody"
android:layout_alignRight="@+id/tvTimeofPost"
android:layout_alignEnd="@id/tvTimeofPost"
android:layout_marginBottom="@dimen/margin_10dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ivPostImage"
android:layout_alignLeft="@+id/ivPostImage"
android:layout_alignStart="@+id/ivPostImage"
android:layout_alignRight="@+id/ivPostImage"
android:layout_alignEnd="@id/ivPostImage"
android:weightSum="3">
<TextView android:id="@+id/tvReply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray" android:layout_weight="1"
android:drawableLeft="@drawable/reply_small" android:layout_below="@+id/ivPostImage"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/tvRetweetCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="@color/gray"
android:drawableLeft="@drawable/retweet_small"
android:layout_weight="1"
android:drawablePadding=".5dp"
android:layout_centerVertical="true"
android:textSize="@dimen/text_size_13sp" android:layout_below="@+id/ivPostImage"
android:layout_alignRight="@+id/tvReply"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/tvFavoriteCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textColor="@color/gray"
android:layout_weight="1"
android:drawableLeft="@drawable/favorite_small"
android:drawablePadding=".5dp"
android:textSize="@dimen/text_size_13sp"
android:layout_below="@+id/ivPostImage"
android:layout_alignRight="@+id/tvRetweetCount"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
</RelativeLayout>
我已经尝试过各种解决方案。。任何帮助都会很好。。提前感谢。在您的else声明中使用以下内容:
viewHolder = (ViewHolder) convertView.getTag();
convertView.setClickable(true);
convertView.setFocusable(true);
您的convertview在绘图时可聚焦和单击,但在重画时不可聚焦和单击。您尝试的各种解决方案是…?我尝试过使用customlisteners,我尝试过在项目的根标记中使用以下属性。\u tweet.xml安卓:genderantFocusability=“blocksDescendants”。我还将列表视图中的所有其他元素设置为android:focusable=“false”和android:focusableInTouchMode=“false”。我还使textView在默认情况下不可选择(android:textIsSelectable=“false”)。根据类似问题的可用解决方案。谢谢
viewHolder = (ViewHolder) convertView.getTag();
convertView.setClickable(true);
convertView.setFocusable(true);