0

I have a listview which contains some cells and the cells contains Buttons.

The buttons work fine on first attempt but after scrolling, they do not work. The state changes to selected but the onClickListener is not getting called.

Here's the xml for the button (they're IconButtons actually see: android-iconify)

        <com.joanzapata.iconify.widget.IconButton
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_gravity="right"
            android:gravity="right|center|top"
            android:paddingRight="30dp"
            android:layout_toRightOf="@id/icon_map_marker"
            android:layout_alignParentRight="true"
            android:textColor="@drawable/hj_button_text_color_blue"
            android:text="{fa-user}"
            android:background="@color/default_transparent_color"
            android:ellipsize="end"
            android:id="@+id/textView_ad_detail_authorName"
            android:maxLines="1"
            android:focusable="false"
            android:textSize="13sp" />

and then in the adapter:

IconButton buttonUsername = (IconButton) adDetailView.findViewById(R.id.textView_ad_detail_authorName);
buttonUsername.setText("\u200F" + "{fa-user 16sp @color/hj_color_blue}" + "  " + ad.getAuthorName() + "  " + "{fa-thumbs-up 16sp @color/hj_color_green}");

buttonUsername.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            IconButton button = (IconButton) view;
                            String username = ad.getAuthorName();
                            if (delegate != null) {
                                try {
                                    delegate.usernamePushed(username, button.getId());
                                }
                                catch (Exception e) {
                                    Crashlytics.logException(e.getCause());
                                }
                            }

                                }

                    });

I already tried this but it did not work for me.

I uploaded a short video to youtube here.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Abdullah Umer
  • 4,234
  • 5
  • 36
  • 65
  • Its too big but I posted the code for the particular button. Let me also add the OnClickListener. – Abdullah Umer Feb 24 '19 at 07:58
  • use `RecyclerView` instead, not `ListView` – pskink Feb 24 '19 at 07:58
  • For now, my min Api target is 18. RecyclerView is added since API 22.1.0. – Abdullah Umer Feb 24 '19 at 08:01
  • 1
    22.1.0? see https://stackoverflow.com/a/34727022/2252830 – pskink Feb 24 '19 at 08:06
  • I will wait for a while and see if I could find and easy fix to current implementation. Otherwise changing to RecyclerView will probably take too much time because the code is too big. Or is there any easy way to switch to RecyclerView? – Abdullah Umer Feb 24 '19 at 08:10
  • I added `listView.notifyDataSetChanged()` in `onScrollStateChanged()` for `SCROLL_STATE_IDLE` and this somehow fixed the issue. I wonder if this is a good fix!? – Abdullah Umer Feb 25 '19 at 08:34

0 Answers0