Button Inside Android ListView doesnt respond to clicks -


i have default listview have added custom views list items, buttons inside of these views not clickable of time. output log.v when button receives click event, have tap button dozen times before register click.

the other problem related tot having when button pressed want animation happen revealing menu sliding out beneath it. @ moment have tried several different methods making custom class views versus using layout inflater relativelayout object view, nothing working properly. have tried using listview.getadapter().notifydatasetchanged(); has pop-into-place extended view when want animation.

i have searched everywhere , seems possible solutions either rewrite own custom listview or use linearlayout scrollview. latter seems easier dont think optimized listview is.

any suggestions appreciated, if need see code, please let me know...

thanks!

update:

the getview() contains this:

    holder hold;     convertview = friends.get(position);     hold = new holder();     hold.pos = position;     convertview.settag(hold);     return convertview; 

basically pass arraylist<relativelayout>, @ moment, adapter dont have create new view each time , animation stay animated when scroll down...

inside oncreate() activity set arraylist<relativelayout> next code, temporary plan use method later, async task or view contains data...

    relativelayout temp;     for(int i=0; i<30; i++){         temp = (relativelayout) inflater.inflate(r.layout.list_item, null);          final linearlayout extralistiteminfo = (linearlayout) temp.findviewbyid(r.id.extralistiteminfo);          button infobtn = (button) temp.findviewbyid(r.id.infobtn);         infobtn.setonclicklistener(new onclicklistener(){             @override             public void onclick(view v) {                 log.v("listitem", "button has been clicked... ");                 extralistiteminfo .setvisibility(view.visible);                  expandanimation closeanim = new expandanimation(extralistiteminfo , animheight);                 closeanim.setduration(750);                 closeanim.setfillafter(true);                  if(extralistiteminfo .gettag() == null || !extralistiteminfo .gettag().equals("expanded")){                     extralistiteminfo .getlayoutparams().height = 0;                     friendinfolist.startanimation(closeanim.expand());                     extralistiteminfo .settag("expanded");                 }else if(extralistiteminfo .gettag().equals("expanded")){                     extralistiteminfo .startanimation(closeanim.collapse());                     extralistiteminfo .settag("closed");                 }                 //((baseadapter) listview.getadapter()).notifydatasetchanged(); tried here once left     //as action inside listview's onitemclick()             }         });          listitems.add(temp);     } 

this list item using:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="@color/darkgrey"     android:paddingbottom="5dp" >      <linearlayout         android:id="@+id/extralistiteminfo "         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/listiteminfo"         android:layout_marginleft="10dp"         android:layout_marginright="10dp"         android:layout_margintop="-10dp"         android:background="@color/grey"         android:orientation="vertical"         android:visibility="gone" >           <relativelayout             android:id="@+id/relativelayout04"             android:layout_width="match_parent"             android:layout_height="@dimen/activity_list_height"             android:layout_margintop="5dp" >              <imageview                 android:id="@+id/imageview04"                 android:layout_width="wrap_content"                 android:layout_height="25dp"                 android:layout_margin="5dp"                 android:src="@drawable/logo_d" />              <textview                 android:id="@+id/textview04"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centervertical="true"                 android:layout_torightof="@+id/imageview04"                 android:text="textview"                 android:textcolor="@color/black"                 android:textsize="17dp" />         </relativelayout>          <relativelayout             android:id="@+id/relativelayout03"             android:layout_width="match_parent"             android:layout_height="@dimen/activity_list_height" >              <imageview                 android:id="@+id/imageview03"                 android:layout_width="wrap_content"                 android:layout_height="25dp"                 android:layout_margin="5dp"                 android:src="@drawable/logo_d" />              <textview                 android:id="@+id/textview03"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centervertical="true"                 android:layout_torightof="@+id/imageview03"                 android:text="textview"                 android:textcolor="@color/black"                 android:textsize="17dp" />         </relativelayout>          <relativelayout             android:id="@+id/relativelayout02"             android:layout_width="match_parent"             android:layout_height="@dimen/activity_list_height" >              <imageview                 android:id="@+id/imageview02"                 android:layout_width="wrap_content"                 android:layout_height="25dp"                 android:layout_margin="5dp"                 android:src="@drawable/logo_d" />              <textview                 android:id="@+id/textview02"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centervertical="true"                 android:layout_torightof="@+id/imageview02"                 android:text="textview"                 android:textcolor="@color/black"                 android:textsize="17dp" />         </relativelayout>          <relativelayout             android:id="@+id/relativelayout1"             android:layout_width="match_parent"             android:layout_height="@dimen/activity_list_height" >              <imageview                 android:id="@+id/imageview1"                 android:layout_width="wrap_content"                 android:layout_height="25dp"                 android:layout_margin="5dp"                 android:src="@drawable/logo_d" />              <textview                 android:id="@+id/textview1"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centervertical="true"                 android:layout_torightof="@id/imageview1"                 android:text="textview"                 android:textcolor="@color/black"                 android:textsize="17dp" />         </relativelayout>          <relativelayout             android:id="@+id/relativelayout01"             android:layout_width="match_parent"             android:layout_height="@dimen/activity_list_height">              <imageview                 android:id="@+id/imageview01"                 android:layout_width="wrap_content"                 android:layout_height="25dp"                 android:layout_margin="5dp"                 android:src="@drawable/logo_d" />              <textview                 android:id="@+id/textview01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centervertical="true"                 android:layout_torightof="@+id/imageview01"                 android:text="textview"                 android:textcolor="@color/black"                 android:textsize="17dp" />         </relativelayout>     </linearlayout>         <relativelayout         android:id="@+id/listiteminfo"         android:layout_width="wrap_content"         android:layout_height="95dp"         android:background="@drawable/friend_cell_background2x"         android:clickable="true" >           <relativelayout             android:id="@+id/leftlayout"             android:layout_width="90dp"             android:layout_height="match_parent" >             <imageview                 android:id="@+id/imgcompany"                 android:layout_width="60dp"                 android:layout_height="50dp"                 android:layout_centerhorizontal="true"                 android:layout_marginleft="10dp"                 android:layout_margintop="10dp"                 android:scaletype="centerinside"                 android:src="@drawable/user2x" />             <imageview                 android:id="@+id/imageview2"                 android:layout_width="40dp"                 android:layout_height="40dp"                 android:layout_alignparentbottom="true"                 android:layout_centerhorizontal="true"                 android:scaletype="fitxy"                 android:src="@drawable/online_indicator2s" />          </relativelayout>           <linearlayout             android:id="@+id/linearlayout1"             android:layout_width="wrap_content"             android:layout_height="50dp"             android:layout_margintop="5dp"             android:layout_torightof="@+id/leftlayout"             android:background="@android:color/transparent"             android:gravity="left|center"             android:orientation="vertical"             android:paddingleft="5dp" >               <textview                 android:id="@+id/lblcompanyname"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="contact name"                 android:textcolor="@color/white"                 android:textsize="18dp"                 android:textstyle="bold" >              </textview>               <textview                 android:id="@+id/lblreawrddesc"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="last played offer"                 android:textcolor="@color/white"                 android:textsize="17dp" >              </textview>         </linearlayout>          <imageview             android:id="@+id/imageview4"             android:layout_width="40dp"             android:layout_height="40dp"             android:layout_alignparentright="true"             android:layout_alignparenttop="true"             android:layout_marginright="5dp"             android:src="@drawable/facebook_btn2x" />         <button             android:id="@+id/infobtn"             style="?android:attr/buttonstylesmall"             android:layout_width="40dp"             android:layout_height="40dp"             android:layout_alignparentbottom="true"             android:layout_alignright="@+id/imageview4"             android:background="@drawable/info_btn2x"             android:clickable="true" />          <textview             android:id="@+id/textview2"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentbottom="true"             android:layout_marginbottom="13dp"             android:layout_toleftof="@+id/infobtn"             android:text="follows 30+"             android:textcolor="@color/white"             android:textsize="11dp" />          <button             android:id="@+id/button1"             style="?android:attr/buttonstylesmall"             android:layout_width="75dp"             android:layout_height="20dp"             android:layout_alignparentbottom="true"             android:layout_marginbottom="10dp"             android:layout_marginright="10dp"             android:layout_toleftof="@+id/textview2"             android:background="@drawable/fan_btn2x"             android:text="fans 30+"             android:textcolor="@color/white"             android:textsize="11dp" />           <imageview             android:id="@+id/imageview5"             android:layout_width="40dp"             android:layout_height="40dp"             android:layout_alignparenttop="true"             android:layout_toleftof="@+id/imageview4"             android:src="@drawable/google_btn2x" />      </relativelayout>  </relativelayout> 

sorry layout problems may make things difficult read... hope helps guys understand problem... thanks

update 2:

all of these answers have been helpful in way, think main issue must first fix why buttons not receive click events until have first scrolled away listitem, it, clicked button again... if can find solution think else easier solve... thanks...

a screenshot requested, remember shot taken on samsung galaxy tab 10.1 , due me using same layout larger screen, looks different on phone test (motorola droid x isnt rooted , cant take screenshots...)

enter image description here

another update: managed clicking , animation working nicely extending arrayadapter instead of base adapter. sadly still experiencing problems bottom half of list clickable. top half of list still behaves before glitchy click events... ideas happening time? thanks...

well isn't answer, after rewriting few times managed fix functions way wanted.

this time left of data separate each view , had each list item custom class inheriting relativelayout , implementing own onclicklistener specific infobtn.

my adapter extends arrayadapter<> , overrides getview() method:

public view getview(int position, view convertview, viewgroup parent) {      if(convertview != null && (convertview instanceof friendlistitem2))         ((friendlistitem2) convertview).setfriendinfo(friends.get(position));     else         convertview = new friendlistitem2(getcontext(), friends.get(position));      return convertview; } 

finally, in main activity page set listview adapter passed data to.

this cleaner had before , wish hadn't taken several rewrites of code right. can benefit this, though still have no clue why getting problem before.

thanks previous suggestions.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -