android - OnClickListener not getting fired for an image button inside a ListView using Custome Adapter -


i have spent time searching solutions , tried different ways couldn't find goes wrong.

i developing app have imagebutton child element of listview (i have done using custom adapters). upon executing onclick of imagebutton, nothing happens.

my fragment_tweets.xml looks follows:

           <?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> 

getview() of adapter looks this:

@override public view getview(int position, view convertview, viewgroup parent) {     final tweet tweet = getitem(position);     final viewholder viewholder;      // if it's retweeted tweet, display original     if (tweet.getretweeted() != null) {         tweettodisplay = tweet.getretweetedstatus();     } else {         tweettodisplay = tweet;     }     if(convertview==null){         viewholder = new viewholder();         layoutinflater inflator = (layoutinflater) getcontext()                 .getsystemservice(context.layout_inflater_service);         convertview = inflator.inflate(r.layout.item_tweet, null);         convertview.setclickable(true);         convertview.setfocusable(true);         viewholder.ivprofilepicture = (imagebutton) convertview.findviewbyid(r.id.ivprofilepicture);     }else{         viewholder = (viewholder) convertview.gettag();     }    viewholder.ivprofilepicture.setimageresource(0); // clear out old image     // rounded image in profile picture     transformation transformation = new roundedtransformationbuilder()             .bordercolor(color.black)             .borderwidthdp(1)             .cornerradiusdp(30)             .oval(false)             .build();     picasso.with(getcontext()).load(tweet.getuser().getprofileimageurl())             .transform(transformation)             .placeholder(r.mipmap.ic_launcher)             .into(viewholder.ivprofilepicture);     log.v("tweets adapter","before onclick of profile pic");     viewholder.ivprofilepicture.settag(tweet.getuser().getscreenname());     viewholder.ivprofilepicture.setfocusable(false);     viewholder.ivprofilepicture.setfocusableintouchmode(false);     viewholder.ivprofilepicture.setclickable(true);     // view listener showing profile of user     viewholder.ivprofilepicture.setonclicklistener(new      view.onclicklistener() {         @override         public void onclick(view view) {              log.v("adapter ", "inside onclick method");             // launch profile activity directly fragment             listener.profileclicked(tweet.getuser());         }     });      return convertview;    } 

i have tried various solutions posted.. great.. in advance..

in else statement use this:

viewholder = (viewholder) convertview.gettag(); convertview.setclickable(true); convertview.setfocusable(true); 

your convertview focusable , clickable when drawing not when redrawing.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -