0

I am trying to design SwipeMenu Listview in Android. But i am facing issues while giving listeners to the parent relative layout of the adapter. So , the SwipeMenu is not coming and from SwipeMenuListView , the onTouchEvent is not getting called.

I follow the this tutorial to design SwipeMenuListView.

MyCode :

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(getApplicationContext(),
                    R.layout.item_list_app, null);
            new ViewHolder(convertView);
        }
        final ViewHolder holder = (ViewHolder) convertView.getTag();
        ApplicationInfo item = getItem(position);

        holder.rlt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(getApplicationContext(), "Click "+position, Toast.LENGTH_SHORT).show();

            }
        });



        holder.iv_icon.setImageDrawable(item.loadIcon(getPackageManager()));
        holder.tv_name.setText(item.loadLabel(getPackageManager()));
        return convertView;
    }

XML :

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" >

<ImageView
    android:id="@+id/iv_icon"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/tv_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@+id/iv_icon"
    android:text="name"
    android:textColor="@android:color/black"
    android:textSize="18sp" />  </RelativeLayout>

In my getView , if i will remove the onclick listener , then swipemenu is working , but if there will be a listener then the touchevent is not working.

So this the above codes of my issue , please suggest me some solution.

MyCode
  • 289
  • 1
  • 5
  • 21
  • 1
    Have you tried to implement OnItemClickListener, giving the fact that the OnClickListener on the rlt layout is basically supposed to do the same thing? – DDsix Jul 23 '15 at 06:18
  • yes in OnItemClickListener is working fine , but i am trying to the same thing in OnClickListener from adapter – MyCode Jul 23 '15 at 06:32
  • 1
    Why do you want to use the click listener on the row instead of just using on item (if you say this one works fine)? Maybe you can do something here to avoid your original problem, like have the adapter implement OnItemClickListener and set it as a listener to the ListView, or pass the ListView in the adapter's constructor and set the listener there – DDsix Jul 23 '15 at 06:35

2 Answers2

1

Just add android:descendantFocusability="blocksDescendants" to your relative layout.This should work. Like :

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:descendantFocusability="blocksDescendants" >

<ImageView
android:id="@+id/iv_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher" />

<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/iv_icon"
android:text="name"
android:textColor="@android:color/black"
android:textSize="18sp" />  
</RelativeLayout>
Akshay Bhat 'AB'
  • 2,690
  • 3
  • 20
  • 32
  • Thanks , i have added your code , but it's not working , is it also required to add some Java Code? Please let me know !!! – MyCode Jul 24 '15 at 07:11
0

I've made a library that has a lot of features like:

  • PullToRefresh
  • SwipeMenu
  • LoadMorePagination
  • SectionIndexer with Pinned Header Item.

You can find the source code from the Github link https://github.com/AbdulRehmanNazar/Android-PullToRefresh-with-SwipeMenu-ListView-and-Section-Indexer Enjoy Coding

IlGala
  • 3,331
  • 4
  • 35
  • 49