android - button in fragmentlist only responds once, then "releases" when clicking on the row -


when click button in listview, see toast once. further clicks don't show when click away button , in empty space in listview, button click events not responding earlier appear @ once (many toasts pop 1 after another). idea how fix this?

    class adapter extends arrayadapter     {          hashmap<integer, view> rowviews = new hashmap<integer, view>();          public adapter(context context) {             super(context, r.layout.manage_member_row, members);         }          @override         public view getview(int position, view convertview, viewgroup parent) {             final view rowview;             if(rowviews.containskey(position)) {                 rowview = rowviews.get(position);             } else {                 rowview = inflater.inflate(r.layout.manage_member_row, parent, false);                 ((textview) rowview.findviewbyid(r.id.manage_member_row_name)).settext(members.get(position).name);                 rowviews.put(position, rowview);             }              ((button) rowview.findviewbyid(r.id.manage_member_row_delete)).setonclicklistener(new view.onclicklistener(){                 public void onclick(view v) {                     // todo auto-generated method stub                     toast.maketext(getapplicationcontext(), "btnclick", toast.length_short).show();                 }             });             log.i("crc", "called");             return rowview;         }     //manage_member_row.xml <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="fill_parent"     android:layout_alignparentbottom="true"     android:descendantfocusability="blocksdescendants"     android:layout_alignparentleft="true"     android:layout_height="wrap_content"     android:paddingtop="8dip"     android:paddingbottom="8dip"     android:background="#ffffff"     android:orientation="vertical">      <textview         android:id="@+id/manage_member_row_name"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="name"         android:textsize="18sp"         android:textcolor="#53585e"         android:gravity="center_vertical"         android:textappearance="?android:attr/textappearancemedium"         android:layout_centervertical="true"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:layout_marginleft="15dp" />      <button         android:id="@+id/manage_member_row_delete"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:paddingtop="0dip"         android:paddingbottom="0dip"         android:paddingleft="8dip"         android:clickable="true"         android:focusable="true"         android:textsize="18sp"         android:textcolor="#4e4e4e"         android:background="#eaeaea"         android:paddingright="8dip"         android:textstyle="bold"         android:text="remove"         android:layout_alignparentright="true"         android:layout_marginright="15dip" /> </relativelayout>       //fragment_manage_members.xml <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="activities.managemembersactivity$placeholderfragment">      <listview         android:layout_width="wrap_content"         android:descendantfocusability="blocksdescendants"         android:layout_margintop="0dip"         android:dividerheight="2.0dip"         android:divider="#eeedf3"         android:layout_height="wrap_content"         android:id="@android:id/list" />  </relativelayout> 

the problem position getview not synchronized have problem before..

also note use hashmap<integer, view> check if view there cost lot of memory , cause outofmemoryexception..

so instead of putting in hashmap create viewholder views. , add object of viewholder tag of view..

example:

@override public view getview(int position, view view, viewgroup viewgroup) {     viewholder viewholder = null;      if(view == null)     {         viewholder = new viewholder();         view = minflater.inflate(r.layout.chat_online_user_list_view_item, null);          viewholder.username = (textview) view.findviewbyid(r.id.chat_online_user_name);          view.settag(viewholder);     }     else         viewholder = (viewholder) view.gettag();      //do on click listener here      return view; }  private class viewholder {     private textview username; } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -