GithubHelp home page GithubHelp logo

wdullaer / swipeactionadapter Goto Github PK

View Code? Open in Web Editor NEW
213.0 12.0 61.0 210 KB

The Mailbox-like Swipe gesture library for Android

License: Apache License 2.0

Java 100.00%
android-library listview swipe-gestures jar android

swipeactionadapter's Introduction

SwipeActionAdapter - The Mailbox-like Swipe gesture library

Maven Central

SwipeActionAdapter is a library that provides a simple API to create Mailbox-like action when swiping in a ListView. The idea is to make it simple enough to implement while still providing sufficient options to allow you to integrate it with the design of your application.

Support for Android 4.0 and up. It might work on lower API versions, but I haven't tested it and I don't intend to make any effort in that direction.

Feel free to fork or issue pull requests on github. Issues can be reported on the github issue tracker.

Normal Swipe Gesture

Far Swipe Gesture

Setup

There are multiple options to add SwipeActionAdapter to your project:

  • Grade
    Add it as a dependency to your build.gradle
dependencies {
    compile 'com.wdullaer:swipeactionadapter:2.0.0'
}
  • Jar File
    Download the jar file and add it to your project

  • Build from source
    If you would like to get the most recent code in a jar, clone the project and run ./gradlew jar from the root folder. This will build a swipeactionadapter.jar in library/build/libs/.

You may also add the library as an Android Library to your project. All the library files live in library.

The library also uses some Java 8 features, which Android Studio will need to transpile. This requires the following stanza in your app's build.gradle. See https://developer.android.com/studio/write/java8-support.html for more information on Java 8 support in Android.

android {
  ...
  // Configure only for each module that uses Java 8
  // language features (either in its source code or
  // through dependencies).
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Creating your ListView with swipe actions

If you'd rather just start with a working example, clone the project and take a look.

For a basic implementation, you'll need to

  1. Wrap the Adapter of your ListView with a SwipeActionAdapter
  2. Create a background layout for each swipe direction you wish to act upon.
  3. Implement the SwipeActionAdapter

Wrap the adapter of your ListView

The majority of this libraries functionality is provided through an adapter which wraps around the content Adapter of your ListView. You will need to set the SwipeActionAdapter to your ListView and because we need to set some properties of the ListView, you will also need to give a reference of the ListView to the SwipeActionAdapter. This is typically done in your Activity's or Fragments onCreate/onActivityCreated callbacks.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create an Adapter for your content
    String[] content = new String[20];
    for (int i=0;i<20;i++) content[i] = "Row "+(i+1);
    ArrayAdapter<String> stringAdapter = new ArrayAdapter<String>(
            this,
            R.layout.row_bg,
            R.id.text,
            new ArrayList<String>(Arrays.asList(content))
    );

    // Wrap your content in a SwipeActionAdapter
    mAdapter = new SwipeActionAdapter(stringAdapter);

    // Pass a reference of your ListView to the SwipeActionAdapter
    mAdapter.setListView(getListView());

    // Set the SwipeActionAdapter as the Adapter for your ListView
    setListAdapter(mAdapter);
}

Create a background layout for each swipe direction

I'm just supplying an empty layout with a background for each direction. You should have a layout for at least SwipeDirection.DIRECTION_NORMAL_LEFT and SwipeDirection.DIRECTION_NORMAL_RIGHT. The other directions are optional. It is important that the background layouts scale properly vertically. The onCreate callback from the previous section now becomes:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create an Adapter for your content
    String[] content = new String[20];
    for (int i=0;i<20;i++) content[i] = "Row "+(i+1);
    ArrayAdapter<String> stringAdapter = new ArrayAdapter<String>(
            this,
            R.layout.row_bg,
            R.id.text,
            new ArrayList<String>(Arrays.asList(content))
    );

    // Wrap your content in a SwipeActionAdapter
    mAdapter = new SwipeActionAdapter(stringAdapter);

    // Pass a reference of your ListView to the SwipeActionAdapter
    mAdapter.setListView(getListView());

    // Set the SwipeActionAdapter as the Adapter for your ListView
    setListAdapter(mAdapter);

    // Set backgrounds for the swipe directions
    mAdapter.addBackground(SwipeDirection.DIRECTION_FAR_LEFT,R.layout.row_bg_left_far)
            .addBackground(SwipeDirection.DIRECTION_NORMAL_LEFT,R.layout.row_bg_left)
            .addBackground(SwipeDirection.DIRECTION_FAR_RIGHT,R.layout.row_bg_right_far)
            .addBackground(SwipeDirection.DIRECTION_NORMAL_RIGHT,R.layout.row_bg_right);
}

Layout code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="?android:listPreferredItemHeight"
    android:background="@android:color/holo_blue_bright">
</LinearLayout>

Implement the SwipeActionListener

The final thing to do is listen to swipe gestures. This is done by implementing the SwipeActionListener. This interface has three methods:

  • boolean hasActions(int position, SwipeDirection direction): return true if you want this item to be swipeable in this direction
  • boolean shouldDismiss(int position, SwipeDirection direction): return true if you want the item to be dismissed, return false if it should stay visible. This method runs on the interface thread so if you want to trigger any heavy actions here, put them on an ASyncThread
  • void onSwipe(int[] position, SwipeDirection[] direction): triggered when all animations on the swiped items have finished. You will receive an array of all swiped items, sorted in descending order with their corresponding directions.

You should pass a reference of your SwipeActionListener to the SwipeActionAdapter

Here's the final implementation of our example's onCreate method:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create an Adapter for your content
    String[] content = new String[20];
    for (int i=0;i<20;i++) content[i] = "Row "+(i+1);
    ArrayAdapter<String> stringAdapter = new ArrayAdapter<String>(
            this,
            R.layout.row_bg,
            R.id.text,
            new ArrayList<String>(Arrays.asList(content))
    );

    // Wrap your content in a SwipeActionAdapter
    mAdapter = new SwipeActionAdapter(stringAdapter);

    // Pass a reference of your ListView to the SwipeActionAdapter
    mAdapter.setListView(getListView());

    // Set the SwipeActionAdapter as the Adapter for your ListView
    setListAdapter(mAdapter);

    // Set backgrounds for the swipe directions
    mAdapter.addBackground(SwipeDirection.DIRECTION_FAR_LEFT,R.layout.row_bg_left_far)
            .addBackground(SwipeDirection.DIRECTION_NORMAL_LEFT,R.layout.row_bg_left)
            .addBackground(SwipeDirection.DIRECTION_FAR_RIGHT,R.layout.row_bg_right_far)
            .addBackground(SwipeDirection.DIRECTION_NORMAL_RIGHT,R.layout.row_bg_right);

    // Listen to swipes
    mAdapter.setSwipeActionListener(new SwipeActionListener(){
        @Override
        public boolean hasActions(int position, SwipeDirection direction){
            if(direction.isLeft()) return true; // Change this to false to disable left swipes
            if(direction.isRight()) return true;
            return false;
        }

        @Override
        public boolean shouldDismiss(int position, SwipeDirection direction){
            // Only dismiss an item when swiping normal left
            return direction == SwipeDirection.DIRECTION_NORMAL_LEFT;
        }

        @Override
        public void onSwipe(int[] positionList, SwipeDirection[] directionList){
            for(int i=0;i<positionList.length;i++) {
                int direction = directionList[i];
                int position = positionList[i];
                String dir = "";

                switch (direction) {
                    case SwipeDirection.DIRECTION_FAR_LEFT:
                        dir = "Far left";
                        break;
                    case SwipeDirection.DIRECTION_NORMAL_LEFT:
                        dir = "Left";
                        break;
                    case SwipeDirection.DIRECTION_FAR_RIGHT:
                        dir = "Far right";
                        break;
                    case SwipeDirection.DIRECTION_NORMAL_RIGHT:
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Test Dialog").setMessage("You swiped right").create().show();
                        dir = "Right";
                        break;
                }
                Toast.makeText(
                        this,
                        dir + " swipe Action triggered on " + mAdapter.getItem(position),
                        Toast.LENGTH_SHORT
                ).show();
                mAdapter.notifyDataSetChanged();
            }
        }
        
        @Override
        public void onSwipeStarted(ListView listView, int position, SwipeDirection direction) {
            // User is swiping
        }
        
        @Override
        public void onSwipeEnded(ListView listView, int position, SwipeDirection direction) {
            // User stopped swiping (lifted finger from the screen)
        }
    });
}

Additional Options

setFadeOut(boolean fadeOut)

Setting this to true will cause the ListView item to slowly fade out as it is being swiped.

setFixedBackgrounds(boolean fixedBackgrounds)

Setting this to true will make the backgrounds static behind the ListView item instead of sliding in from the side.

setDimBackgrounds(boolean dimBackgrounds)

Setting this to true will make the backgrounds appear dimmed before the normal swipe threshold is reached.

setNormalSwipeFraction(float normalSwipeFraction)

Allows you to set the fraction of the view width that must be swiped before it is counted as a normal swipe. The float must be between 0 and 1. 0 makes every swipe register, 1 effectively disables swipe.

setFarSwipeFraction(float farSwipeFraction)

Allows you to set the fraction of the view width that must be swiped before it is counted as a far swipe. The float must be between 0 and 1. 0 makes every swipe a far swipe, 1 effectively disables a far swipe.

onSwipeStarted and onSwipeEnded

You can use these events to execute code once the user starts or stops swiping in a listItem. This can be used to fix issues relating to other libraries hijacking touch events (for example; a SwipeRefreshLayout).

@Override
public void onSwipeStarted(ListView listView, int position, SwipeDirection direction) {
}

@Override
public void onSwipeEnded(ListView listView, int position, SwipeDirection direction) {
}

License

Copyright (c) 2014 Wouter Dullaert

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

swipeactionadapter's People

Contributors

intrications avatar j4zen avatar leosimas avatar mikkysati avatar wdullaer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swipeactionadapter's Issues

error when i try to filter my adapter

this is my code

package com.my.package;


import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.design.widget.BottomSheetDialog;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FilterQueryProvider;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.Toast;

import com.wdullaer.swipeactionadapter.SwipeActionAdapter;
import com.wdullaer.swipeactionadapter.SwipeDirection;


public class MainActivity extends AppCompatActivity {
    private BottomSheetDialog bottomSheetDialog;
    private SimpleCursorAdapter mycursoradapter;
    private ListView mylist;
    private DataBaseAdapter myDB;
    SwipeActionAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bottomSheetDialog = new BottomSheetDialog(this);
        View bottomsheetview = getLayoutInflater().inflate(R.layout.addbottomsheet, null);
        bottomSheetDialog.setContentView(bottomsheetview);
        LinearLayout addnewbtn = (LinearLayout) bottomSheetDialog.findViewById(R.id.addnewbtn);
        LinearLayout addexistbtn = (LinearLayout) bottomSheetDialog.findViewById(R.id.addexistbtn);

        addnewbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, AddNewContact.class));
                bottomSheetDialog.dismiss();
            }
        });
        addexistbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShowToast("add exist");

            }
        });

        openDB();
        populateListView();

        mAdapter.setSwipeActionListener(new SwipeActionAdapter.SwipeActionListener() {
            @Override
            public boolean hasActions(int i, SwipeDirection swipeDirection) {
                if (swipeDirection.isLeft())
                    return true; // Change this to false to disable left swipes
                if (swipeDirection.isRight()) return true;
                return false;
            }

            @Override
            public boolean shouldDismiss(int i, SwipeDirection swipeDirection) {
                // Only dismiss an item when swiping normal left
                return false; //swipeDirection == swipeDirection.DIRECTION_NORMAL_LEFT;
            }

            @Override
            public void onSwipe(int[] positionList, SwipeDirection[] directionList) {
                for (int i = 0; i < positionList.length; i++) {
                    SwipeDirection direction = directionList[i];
                    int position = positionList[i];
                    String dir = "";


                    switch (direction) {
                        case DIRECTION_FAR_LEFT:
                            dir = "Far left";
                            break;
                        case DIRECTION_NORMAL_LEFT:
                            dir = "Left";
                            break;
                        case DIRECTION_FAR_RIGHT:
                            dir = "Far right";
                            break;
                        case DIRECTION_NORMAL_RIGHT:
                            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                            builder.setTitle("Test Dialog").setMessage("You swiped right").create().show();
                            dir = "Right";
                            break;
                    }

                    Toast.makeText(getApplicationContext(), dir + " swipe Action triggered on " + mAdapter.getItem(position), Toast.LENGTH_SHORT).show();
                    mAdapter.notifyDataSetChanged();
                }
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.action_bar, menu);


        SearchView searchView = (SearchView) menu.findItem(R.id.app_bar_search).getActionView();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                mylist = (ListView) findViewById(R.id.ListConfessioner);
                SimpleCursorAdapter filterAdapter = (SimpleCursorAdapter) mylist.getAdapter();
                filterAdapter.getFilter().filter(newText.toString());
                SwipeActionAdapter mAdapter = new SwipeActionAdapter(filterAdapter);
                mAdapter.setListView(mylist);
                return false;
            }
        });
        mycursoradapter.setFilterQueryProvider(new FilterQueryProvider() {
            @Override
            public Cursor runQuery(CharSequence constraint) {

                return myDB.searchname(constraint);
            }
        });
        return super.onCreateOptionsMenu(menu);


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
//handle presses on the actionbar items
        switch (item.getItemId()) {
            case R.id.app_bar_search:

                return true;
            case R.id.btnadd_contact:
               
                bottomSheetDialog.show();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void ShowToast(String Text) {
        Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
    }

    private void openDB() {
        myDB = new DataBaseAdapter(this);
        myDB.open();
    }

    public void populateListView() {
        Cursor cursor = myDB.searchname(null);
        String[] fromFieldNames = new String[]{myDB.KEY_ROWID, myDB.KEY_NAME, myDB.KEY_DATE};
        int[] toviewIDs = new int[]{R.id.textViewpnumber, R.id.textViewpname, R.id.textViewdate};
        mycursoradapter = new SimpleCursorAdapter(this, R.layout.item_layout, cursor, fromFieldNames, toviewIDs, 0);
        mylist = (ListView) findViewById(R.id.ListConfessioner);
        mAdapter = new SwipeActionAdapter(mycursoradapter);
        mAdapter.setListView(mylist);
        mylist.setAdapter(mAdapter);
        mAdapter.addBackground(SwipeDirection.DIRECTION_NORMAL_LEFT, R.layout.row_bg_left);
        mAdapter.addBackground(SwipeDirection.DIRECTION_NORMAL_RIGHT, R.layout.row_bg_right);
        mylist.setFastScrollEnabled(true);
        mylist.setTextFilterEnabled(true);
    }


}
``
this is the error
java.lang.ClassCastException: com.wdullaer.swipeactionadapter.SwipeActionAdapter cannot be cast to android.support.v4.widget.SimpleCursorAdapter

how can i solve it
i want to filter my listview and keep the swipe option after filtering 

Combine SwipeActionListener and other touch events

Thank you for good swipe solution! Could you please help me with other event listeners: for my ListView I need your onSwipe method as well as single tap and long tap.
For instance only ListView scrolling works. If I use listview.setOnItemClickListener, swipe one doesnt' work anymore.

Error in Swipe action

I add SwipeActionAdapter and implements SwipeActionListener.

i45h93i

When i swipe listView's element hasAction method runs and i have error

sax12qu

My adapter

qro31nb

List item height not adjusted after removing element

If I remove an element from the list, the element that is now at the element's position inherits the height of the removed element.

This is because SwipeActionAdapter.getView() is too aggressive when it recycles it's backgrounds and does not resize the background to fit the new foreground.

I think the right way to do this is to check if contentView's height has changed and if so re-inflate the background.

A work around is to wrap SwipeActionAdapter with a NonRecyclingAdapter such as:

    private static class NonRecyclingAdapter extends DecoratorAdapter {
        public NonRecyclingAdapter(BaseAdapter baseAdapter) {
            super(baseAdapter);
        }

        @Override
        public View getView(final int position, final View convertView, final ViewGroup parent) {
            return super.getView(position, null, parent);
        }
    }

mAdapter.setFadeOut(true)

mAdapter = new SwipeActionAdapter(stringAdapter);
mAdapter.addBackground(SwipeDirection.DIRECTION_NORMAL_RIGHT, R.layout.row_bg_right)
.addBackground(SwipeDirection.DIRECTION_NORMAL_LEFT, R.layout.row_bg_left)
.setSwipeActionListener(this)
.setFadeOut(true)

So, While i set .setFadeOut(true), background layout does not show.

It shows only white background.

Waiting for your replay

Thanks,

SwipeRefreshLayout touch events collide with SwipeActionAdapter

Hi,

I'm using your library in a SwipeRefreshLayout (to allow for pull down refresh mechanism).
Unfortunately it seems that the pullToRefresh feature hijacks touch events.

For example, if you have the following layout;

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/listViewItems"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

And use your SwipeActionAdapter on the ListView listViewItems, when you swipe left for a little bit; then swipe down a little bit (not fully engaging the pullToRefresh in the SwipeRefreshLayout), you can no longer continue to swipe within the item you started swiping in.

The only solution (that I'm aware of) is to disable the swipeRefreshLayout if the user started started swiping, to prevent it from hijacking the touch events in SwipeActionAdapter.
This is currently not possible as there are no events available to indicate when a user started and stopped swiping an item.

This would allow me to do;

            @Override
            public void onSwipeStarted(ListView listView, int position, SwipeDirection direction) {
                swipeRefresh.setEnabled(false);
            }

            @Override
            public void onSwipeEnded(ListView listView, int position, SwipeDirection direction) {
                swipeRefresh.setEnabled(true);
            }

Which fixes the problem.

Regards,
Jeroen

Make Swipe stop?

hey there!
would it be possible to define a swipe max? Like you can only swipe away half of the row? In addition, to keep the background and the row visible until I swipe back?

See Attachment :)
16-04-_2015_21-30-05

Action Mode for listview not working properly when I use SwipeActionAdapter

For my listview I have multiselect action mode, with following background selector for item layout

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="true" android:drawable="@color/md_grey_400"/>
    <item android:drawable="@android:color/transparent" />
</selector>

But when I've added SwipeActionAdapter, list item is not styled correctly on click (not become gray). I assume it's because my main layout not activated anymore.

Is there idea how to fix this, I would love to use this library in my project as it very easy to use and it gives what I need. Thanks for any help.

Listview background

Hi,
I have used a little bit that library, but I am unable to change the background colour of the listview(ie when it's empty i just have plain white) is there any way doing it, the way it is built with the row_bg.xml layouts for every item?
Thanks

Change background after swipe

Is it possible to keep the "swiped background" until I swipe back?

For example: I would like to delete the row if I swipe to the right and show some extra information if I'm swiping to the left (until I swipe back). I couldn't find an easy implementation with the current library.

Wouldn't it be make sense to pass this as an additional argument in the mAdapter.addBackground(...) function?
Thanks

Custom adapter

Your swipe Action adapter takes only base adapter. any way to add custom adapter?

Horizontal Scroll View inside my List-item is not working

I've Horizontal Scroll view inside my every list-item but its scroll is not working. Whenever i try to swipe the horizontal scroll view, list-item swipe actions is called. Would you please tell me how to fix this? or any other alternative to horizontal scroll view?

Not working with PullToRefresh

I have to implement SwipeToDelete while swipe from Right to Left & SwipeToSave while swipe from Left to Right.
But i have to implement this functionality in PullToRefreshListView.

So give me suggestion or upload your library if possible

Thanks

Layouts action

Hi dude ,
Iam new to android , and i need help , i need to make actions on the layouts that appear on swipe , how ???

No way to stop animations

There is no way to stop swipe animations from running. Looks like SwipeActionTouchListener controls animations and only starts them, never stopping them.

Example use case:

  1. User starts swiping, animation starts
  2. User minimizes screen (onPause occurs), animation continues
  3. Animation finishes while screen is minimized

When onPause is called, clients should be able to stop all animations (standard practice). 2 issues arise:

  1. Animations continues when user is not on the screen (unnecessary performance hit)
  2. The listener fires when the app does not care about the result

I have removed the listener in onPause so that callbacks won't be executed (solves 2), however, it would be great to be able to stop the animations from running.

Lag Animations

Hello.
When i use a normal layout, with just a background color my animation is very smooth, but when i add one imageview to the layout i have a animation with lag.

Unable to implement SwipeActionAdapter in a simple Activity with a ListView

I'm unable to implement SwipeActionAdapter on a Non-ListActivity (just a simple ActionBarActivity) with an independent ListView. The code builds and runs, but the rows do not slide on swiping. Here's what my onCreate looks like:

public class HomeActivity extends ActionBarActivity {
    // ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // ...

        friendList = (ListView) findViewById (R.id.friendsList);
        friendAdapter = new FriendListAdapter(this, friends);
        swipeAdapter  = new SwipeActionAdapter(friendAdapter);

        swipeAdapter.setListView(friendList);
        friendList.setAdapter(swipeAdapter);

        swipeAdapter
                .addBackground(SwipeDirections.DIRECTION_NORMAL_LEFT,  R.layout.row_bg_green)
                .addBackground(SwipeDirections.DIRECTION_NORMAL_RIGHT, R.layout.row_bg_yellow);

        // ...
    }

// ...

And here's my layout:

<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"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@color/bgColor" >

    <!-- Other Views... -->

    <LinearLayout
        android:orientation="vertical"
        android:layout_below="@+id/infoText"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_above="@+id/statusSwitch"
        android:layout_marginBottom="10dp" >

        <ListView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/friendsList"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:scrollbars="none"/>

    </LinearLayout>
</RelativeLayout>

Custom view

Unable to customize the view of background. it is always throwing me with null pointer exception.

how to customize with two image views for background.

Problem with static background

When fixed backgrounds is set to true (adapter.setFixedBackgrounds(true);), this happens:
example1

When not, this happens:
example2

Is it possible to combine them? To get the swiping in example 2 and the icons in example 1?

EditText dont work

Hi, Thanks for this adapter. I am using a custom adapter in my project that has autocompletetextbox, edittext and few spinners. As soon as I add this adapter autocomplete and edittext dont work. I can't click on them and change values. looks like listeners aren't responding properly. May be its how its designed. Please suggest.

Mixed list

Can I create list where items can have different background?

List View with 2 different List Item heights

Hello,

I have a simple list view fragment that has 2 different items. First being the "section header" which separates my sections. Second being the actual list item content.

My list item "section header" height is set to wrap content, while I have a defined height (82dp) from the list item content.

I have two corresponding layout items (also at 82dp) that represent whats seen when swiping left and right. That works great.

However I'm something a strange bit of extra space (a couple of pixels) after my "section title" when the "addBackground" is applied to the swipe list view. If I remove it (the code below in particular) it doesn't include that extra space.

Is the issue issue due to the "section header"? I have code implemented so that swipe action does not occur on the section header.

Thanks!

                    .setSwipeActionListener(vbf)
                    .addBackground(SwipeDirections.DIRECTION_FAR_LEFT, R.layout.view_venue_beer_mark_blown)
                    .addBackground(SwipeDirections.DIRECTION_NORMAL_LEFT, R.layout.view_venue_beer_mark_blown)
                    .addBackground(SwipeDirections.DIRECTION_FAR_RIGHT, R.layout.view_venue_beer_mark_seen)
                    .addBackground(SwipeDirections.DIRECTION_NORMAL_RIGHT, R.layout.view_venue_beer_mark_seen)

Can I use ArrayAdapter with button and SwipeActionAdapter?

Hello

I have custom ArrayAdapter with button and want to use SwipeActionAdapter for extra features.
Now I have a problem with button because when I click on button on the first item in the ListView the state of item is not changed but when I click on button on another item in the ListView state is changed on the previous item in ListView.

Please let me know if my question is not clear I will provide examples, code and screenshots.

Thx in advance

Render problem

I am stuck on this error/bug and i need help. Adapter still throwing this error:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.wdullaer.swipeactionadapter.SwipeViewGroup.showBackground(com.wdullaer.swipeactionadapter.SwipeDirection, boolean)' on a null object reference
                                                                        at com.wdullaer.swipeactionadapter.SwipeActionTouchListener.onTouch(SwipeActionTouchListener.java:419)
                                                                        at android.view.View.dispatchTouchEvent(View.java:9290)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2547)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                        at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403)
                                                                        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737)
                                                                        at android.app.Activity.dispatchTouchEvent(Activity.java:2765)
                                                                        at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:63)
                                                                        at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:63)
                                                                        at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364)
                                                                        at android.view.View.dispatchPointerEvent(View.java:9514)
                                                                        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230)
                                                                        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096)
                                                                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
                                                                        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
                                                                        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
                                                                        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
                                                                        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
                                                                        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
                                                                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
                                                                        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
                                                                        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
                                                                        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
                                                                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
                                                                        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922)
                                                                        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896)
                                                                        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857)
                                                                        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6025)
                                                                        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                        at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
                                                                        at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
                                                                        at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5996)
                                                                        at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6048)
                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                        at android.view.Choreographer.doCall

I copied the code from samples, so this is my code:

    final ListView listView = (ListView) findViewById(R.id.listview_predmety);
    final SwipeActionAdapter adapter = new SwipeActionAdapter(new Adapter(getApplicationContext()));
    adapter.setListView(listView);
    listView.setAdapter(new Adapter(getApplicationContext())); /*Adapter shown below*/

    adapter.addBackground(SwipeDirection.DIRECTION_NORMAL_LEFT, R.layout.rowbg_predmety_left)
            .addBackground(SwipeDirection.DIRECTION_NORMAL_RIGHT, R.layout.rowbg_predmety_right);
    adapter.setFarSwipeFraction(1);

    adapter.setSwipeActionListener(new SwipeActionAdapter.SwipeActionListener() {
        @Override
        public boolean hasActions(int position, SwipeDirection direction){
            if(direction.isLeft()) return true; // Change this to false to disable left swipes
            if(direction.isRight()) return true;
            return false;
        }

        @Override
        public boolean shouldDismiss(int position, SwipeDirection direction){
            // Only dismiss an item when swiping normal left
            return direction == SwipeDirection.DIRECTION_NORMAL_LEFT;
        }

        @Override
        public void onSwipe(int[] positionList, SwipeDirection[] directionList){
            for(int i=0;i<positionList.length;i++) {
                SwipeDirection direction = directionList[i];
                int position = positionList[i];
                String dir = "";

                if(direction.equals(SwipeDirection.DIRECTION_NORMAL_LEFT)){
                    dir = "Left";
                } else if(direction.equals(SwipeDirection.DIRECTION_NORMAL_RIGHT)){
                    AlertDialog.Builder builder = new AlertDialog.Builder(PredmetyActivity.this);
                    builder.setTitle("Test Dialog").setMessage("You swiped right").create().show();
                    dir = "Right";
                }
                try {
                    String s = listView.getItemAtPosition(position).toString();
                    Log.d(TAG, "onSwipe: " + s);
                } catch (NullPointerException e){
                    e.printStackTrace();
                }
                Toast.makeText(
                        getApplicationContext(),
                        dir + " swipe Action triggered on " + position,
                        Toast.LENGTH_SHORT
                ).show();
                adapter.notifyDataSetChanged();
            }
        }
    });

Adapter:

private class Adapter extends BaseAdapter{

    private final Context context;
    private final LayoutInflater inflater;

    public Adapter(Context context) {
        this.context = context;;
        inflater = (LayoutInflater)context.
                getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        Cursor cursor = GlobalValues.getDatabase(getApplicationContext()).getData("select count(*) from Subjects");
        cursor.moveToFirst();
        String count = cursor.getString(0);
        return Integer.parseInt(count);
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.activity_listview_row, null);

        Cursor cursor = GlobalValues.getDatabase(context).getData("select Name, BasicImage, ProImage from Subjects");
        cursor.moveToPosition(i);

        ImageView image = (ImageView) layout.findViewById(R.id.image);
        if(cursor.getString(2) != null)
            image.setImageResource(getResources().getIdentifier(cursor.getString(2).replace(".png", ""), "drawable", context.getPackageName()));
        else image.setImageResource(android.R.color.transparent);

        TextView textView = (TextView) layout.findViewById(R.id.text);
        textView.setText(cursor.getString(0));
        return layout;
    }
}`

Please someone help me

Different row layouts in one listview

Hi, another problem I was facing, and I am not sure if it is possible to be changed the way it is constructed, is if we can have multiple(different) row layouts according the the listview items.
For example , just changing the background colour of an image of a row layout, according to a listview variable (as the adapter wraps the listview).
Thanks

java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.View$OnTouchListener.onTouch(android.view.View, android.view.MotionEvent)' on a null object reference

02-23 17:54:32.444  1926  1926 E AndroidRuntime: FATAL EXCEPTION: main
02-23 17:54:32.444  1926  1926 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.View$OnTouchListener.onTouch(android.view.View, android.view.MotionEvent)' on a null object reference
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at com.wdullaer.swipeactionadapter.SwipeViewGroup.onInterceptTouchEvent(SwipeViewGroup.java:174)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2108)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.app.Activity.dispatchTouchEvent(Activity.java:2771)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.View.dispatchPointerEvent(View.java:9520)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6025)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.os.MessageQueue.nativePollOnce(Native Method)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.os.MessageQueue.next(MessageQueue.java:323)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:135)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5417)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-23 17:54:32.444  1926  1926 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Failed to find: com.wdullaer.swipeactionadapter:1.3.0

I'm using Android Studio and trying to use your SwipeActionAdapter. After adding the dependency and Syncing, it gives me the error:

Gradle project sync failed. Basic functionality (i.e. editing, debugging) will not work properly.
Error:Failed to find: com.wdullaer.swipeactionadapter:1.3.0:

screen shot 2014-12-29 at 6 43 33 am

Enable/Disable swipe in one direction depending on position

This is a feature request; To allow swipe in only one direction for Rows (or both depending on the requirements). This would mean replacing hasActions with two methods: swipesLeft and swipesRight:

// Example Implementation

@Override
public boolean swipesLeft(int position) {
    // Swipe Left for only Odd Rows
    return position % 2 == 1;
}

@Override    
public boolean swipesRight(int position) {
    // Swipe Right for only Even Rows
    return position % 2 == 0;
}

Issue with ExpandableListView

Hi,

I am using an ExpandableListView instead of the normal ListView. When wrapping my BaseExpandableListAdapter inside SwipeActionAdapter, its giving an error.

Is there a way to make it work?

Thanks in advance

NoClassDefFoundError

While i am importing this library in my project. it will give these errors NoClassDefFoundError ,i am using eclipse Mars 1.
i have import library as a JAR.
logTXT.txt

ListView.CHOICE_MODE_MULTIPLE_MODAL issue

I'm using the ListView.CHOICE_MODE_MULTIPLE_MODAL with AbsListView.MultiChoiceModeListener.

It works great, the items on the listview get checked on LongClick.

But when using it with the SwipeActionAdapter, the views don't change to the checked state although the onItemCheckedStateChanged is fired.

Position issue on custom adapter.

Hi,
I really like this adapter but I have an issue with my custom adapter. What i wanna do is every swipe it juts increment the txtNumber (TextView) on current selected items. But what happened is some of the items also incrementing. attached is my current codes:

public void onSwipe(int[] positionList, int[] directionList, ListView listView) {
TextView selectedText;
for(int i=0;i<positionList.length;i++) {
int direction = directionList[i];
int position = positionList[i];
switch (direction) {
case SwipeDirections.DIRECTION_FAR_LEFT:

                selectedText = (TextView) getViewByPosition(position, listView).findViewById(R.id.txtNumber);
                selectedText.setText(String.valueOf(Integer.parseInt(selectedText.getText().toString()) + 1));

                break;

            case SwipeDirections.DIRECTION_FAR_RIGHT:

                selectedText = (TextView) getViewByPosition(position,listView).findViewById(R.id.txtNumber);
                if (Integer.parseInt(selectedText.getText().toString()) != 0) {
                    selectedText.setText(String.valueOf(Integer.parseInt(selectedText.getText().toString()) - 1));
                }
                break;

            default: break;
        }
        mAdapter.notifyDataSetChanged();
    }

}

public View getViewByPosition(int pos, ListView listView) {
    final int firstListItemPosition = listView.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

    if (pos < firstListItemPosition || pos > lastListItemPosition ) {
        return listView.getAdapter().getView(pos, null, listView);
    } else {
        final int childIndex = pos - firstListItemPosition;
        return listView.getChildAt(childIndex);
    }
}
public void convertStringToArray(String data) {
    JSONArray jsonArray = null;
    try {
        jsonArray = new JSONArray(data);

    } catch (JSONException e) {
        e.printStackTrace();
    }
    String[] strArr = new String[jsonArray.length()];
    ArrayList<String> arrayList = new ArrayList<String>();

    for (int i = 0; i < jsonArray.length(); i++) {
        try {

            strArr[i] = jsonArray.getJSONObject(i).getString("name");
            arrayList.add(jsonArray.getString(i));

            System.out.println(strArr[i]);


            ArrayAdapter<String> stringAdapter = new ArrayAdapter<String>(
                    this,
                    R.layout.foods_extra,
                    R.id.txtName,
                    new ArrayList<String>(Arrays.asList(strArr))
            );

            mAdapter = new SwipeActionAdapter(stringAdapter);
            mAdapter.setSwipeActionListener(this).setListView(getListView());

            mAdapter.addBackground(SwipeDirections.DIRECTION_FAR_LEFT, R.layout.row_bg_left)
                    .addBackground(SwipeDirections.DIRECTION_FAR_RIGHT, R.layout.row_bg_right);

            setListAdapter(mAdapter);
            stringAdapter.notifyDataSetChanged();


        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

Thanks, please help.

Backward compatiblity (Nine Old Android ?)

Have you tried to use NineOldAndroid to make you libary backward compatible to lower than 4.0.0 ?

I've tried but it generates a bunch of glitches on old terminals :/

Working with StickyListHeaders

Hi,

I'm trying to use swipe adapter with StickyListHeaders.
https://github.com/emilsjolander/StickyListHeaders

I think I'm close to a solution, however when I swipe on a row I get the following immediate exception. It does however hit the "hasActions" method

08-02 11:33:07.364    1655-1655/com.slaptap.tappedin E/InputEventReceiver﹕ Exception dispatching input event.
08-02 11:33:07.364    1655-1655/com.slaptap.tappedin E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
08-02 11:33:07.380    1655-1655/com.slaptap.tappedin E/MessageQueue-JNI﹕ java.lang.NullPointerException
            at com.wdullaer.swipeactionadapter.SwipeActionTouchListener.onTouch(SwipeActionTouchListener.java:419)
            at android.view.View.dispatchTouchEvent(View.java:7701)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)

I am setting things up like so inside of a Fragment

            mAdapter = new VenueBeerListAdapter(getActivity(), data);

            listView.setAdapter(mAdapter);

            swipeAdapter = new SwipeActionAdapter(mAdapter);

            swipeAdapter.setListView(listView.getWrappedList())
                    .setSwipeActionListener(vbf)
                    .addBackground(SwipeDirections.DIRECTION_FAR_LEFT, R.layout.view_venue_beer_mark_blown)
                    .addBackground(SwipeDirections.DIRECTION_NORMAL_LEFT, R.layout.view_venue_beer_mark_blown)
                    .addBackground(SwipeDirections.DIRECTION_FAR_RIGHT, R.layout.view_venue_beer_mark_seen)
                    .addBackground(SwipeDirections.DIRECTION_NORMAL_RIGHT, R.layout.view_venue_beer_mark_seen).notifyDataSetChanged();

Any initial thoughts on what I might be doing wrong? I can provide more info if need.. really appreciate the help :)

StickyListHeaders and SwipeActionAdapter

I use the StickyListheaders (https://github.com/emilsjolander/StickyListHeaders) and wants to add the SwipeActionAdapter.

Does anyone have done this?
The problem is that the "StickyList" needs an "StickyListHeadersAdapter".

My CusrsorAdapter implements the "StickyListHeadersAdapter" and I set it to the "StickyListHeadersListView" without "SwipeActionAdapter".

Now I set the CursorAdapter to the "SwipeActionAdapter" and want to set the "SwipeActionAdapter" to the "StickyListHeadersListView", but this does not work because "SwipeActionAdapter" does not implement "StickyListHeadersAdapter"!

How can I solve this? Or does it not work to use this both?

Bug: Background Layout doesn't appear on swiping back and forth

I don't really think I can explain this issue. It's better if I show you:

GIF 1: When swiping back and forth on a row while keeping the touchPoint inside the row, it works fine. But when the touchPoint goes outside the row, only the last appearing Background Layout is visible.

GIF 2: If you bring the touchPoint back inside the row while the background layout that was supposed to be visible (but isn't), it suddenly appears.

Image 1 Image 2

How can I process the conflict when the ListView Item contains some clickable views?

Hello, the Item in my ListView is segmented into some parts, and each part is clickable.

When the child is clickable, the touch event will be intercept by child, so the ListView Item can't be swiped.

However,the ListView still can be scrolled as expected.

My Question is how can I make ListView Item be swiped as normal , when it is segmented into some clickable views?

Thank you for help.

Swipe only one direction

Is possible to implement in the call hasActions also the direction? For example, to make possible swiping only to the right

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.