android - List view updates view which are not touched -


sorry bad title.

i adding toggle button @ run-time list view. when click on button state gets changed. problem when scroll down other items selected too.

for example, if click on first toggle button 6th toggle button gets checked too.

this weird behavior.

here xml code acitivty

        <?xml version="1.0" encoding="utf-8"?>     <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical">          <relativelayout             android:id="@+id/title_bar"             android:layout_width="match_parent"             android:layout_height="50dp"             android:background="@color/eros_now_title_bar">              <imageview                 android:id="@+id/back_button_image"                 android:layout_width="@dimen/toolbar_imageview_width_height"                 android:layout_height="@dimen/toolbar_imageview_width_height"                 android:layout_centervertical="true"                 android:layout_margin="@dimen/back_image_margin"                 android:src="@drawable/ic_arrow_back" />              <imagebutton                 android:id="@+id/back_button"                 android:layout_width="@dimen/toolbar_imagebutton_width_height"                 android:layout_height="@dimen/toolbar_imagebutton_width_height"                 android:layout_centervertical="true"                 android:layout_marginright="20dp"                 android:background="@drawable/npd_back_feedback" />              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_aligntop="@+id/back_button_image"                 android:layout_torightof="@+id/back_button"                 android:fontfamily="sans-serif-regular"                 android:text="invite friends"                 android:textcolor="@color/white"                 android:textsize="18sp"                 android:textstyle="bold" />          </relativelayout>          <edittext             android:id="@+id/search_text"             android:layout_width="match_parent"             android:layout_height="50dp"             android:layout_below="@+id/title_bar"             android:layout_margin="15dp"             android:hint="search"             android:textcolorhint="@color/hint_color"             android:drawableright="@drawable/search_blue_white"/>          <listview             android:id="@+id/friends_list"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_below="@+id/search_text"             android:layout_above="@+id/invite_count_view"             android:layout_margintop="15dp"             android:divider="@color/transparent">          </listview>          <relativelayout             android:id="@+id/invite_count_view"             android:layout_width="match_parent"             android:layout_height="56dp"             android:layout_alignparentbottom="true">              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:fontfamily="sans-serif-light"                 android:textsize="18sp"                 android:textcolor="@color/eros_now_title_bar"                 android:text="10 more invites go"                 android:layout_centerinparent="true"                 />               </relativelayout>     </relativelayout> 

here xml code view inflating in adapter

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/card_view"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="wrap_content"     android:paddingtop="10dp"     android:paddingbottom="10dp">      <com.makeramen.roundedimageview.roundedimageview         xmlns:app="http://schemas.android.com/apk/res-auto"         android:id="@+id/person_pic"         android:layout_width="60dp"         android:layout_height="60dp"         android:layout_marginleft="26dp"         android:layout_centervertical="true"         app:riv_corner_radius="50dip"         android:src="@drawable/ic_person_grey600_36dp"/>      <textview         android:id="@+id/name"         android:layout_width="150dp"         android:layout_height="wrap_content"         android:singleline="true"         android:layout_torightof="@+id/person_pic"         android:layout_marginleft="17dp"         android:layout_centervertical="true"         android:textcolor="@color/black"         android:fontfamily="sans-serif-regular"         android:textsize="16sp"         android:text="grumpy brother"         android:ellipsize="end"/>      <!--<togglebutton-->         <!--android:layout_width="wrap_content"-->         <!--android:layout_height="wrap_content"-->         <!--android:layout_alignparentright="true"-->         <!--android:layout_marginright="35dp"-->         <!--android:layout_centervertical="true"-->         <!--android:background="@drawable/invite_selector"-->         <!--android:texton=""-->         <!--android:textoff=""-->         <!--android:text="" />-->  </relativelayout> 

here code getview

public view getview(int i, view convertview, viewgroup parent) {  log.e("getview", "name = " + contacts.get(i).getname());  if (convertview == null) {     convertview = layoutinflater.from(activity).inflate(r.layout.friend_view, parent, false); }     textview name = (textview) convertview.findviewbyid(r.id.name);     roundedimageview image = (roundedimageview) convertview.findviewbyid(r.id.person_pic);      togglebutton selector = new togglebutton(activity);     if (sdk < android.os.build.version_codes.jelly_bean)         selector.setbackgrounddrawable(activity.getresources().getdrawable(r.drawable.ic_add_black_24dp));     else         selector.setbackground(activity.getresources().getdrawable(r.drawable.ic_add_black_24dp));      relativelayout.layoutparams params = new relativelayout.layoutparams(viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content);     params.addrule(relativelayout.center_vertical, relativelayout.true);     params.addrule(relativelayout.align_parent_end, relativelayout.true);     params.setmargins(0, 0, getpx(35), 0);     selector.setlayoutparams(params);     selector.settextoff("");     selector.settext("");     selector.settexton("");     selector.setoncheckedchangelistener(this);     selector.settag(string.valueof(i));     selector.setchecked(contacts.get(i).getselectedstate());     contacts.get(i).setbutton(selector);     relativelayout card = (relativelayout) convertview.findviewbyid(r.id.card_view);      card.addview(selector);      try {         bitmap bitmap = mediastore.images.media.getbitmap(activity.getcontentresolver(), contacts.get(i).geturi());     } catch (ioexception e) {         contacts.get(i).seturi(uri.parse(""));     }      name.settext(contacts.get(i).getname());     if (!contacts.get(i).geturi().tostring().equals(""))         image.setimageuri(contacts.get(i).geturi());     else         image.setimagedrawable(activity.getresources().getdrawable(r.drawable.ic_person));  return convertview; 

}

i saw used contacts.get(i).getselectedstate() set togglebutton state in getview.

did use adapter.notifydatasetchanged() update listview's state?

if not, add code after toggle button.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -