Implementing 47degree android-swipelistview for swiping android ListViewItem

ε祈祈猫儿з 提交于 2019-12-01 15:32:24
GDroid

Finally, I've managed to integrate Android-SwipeListView library by 47Degrees into my own application.

Works like a charm. Thanks to 47Degrees for writing such a wonderful piece of code.

Solution:

What doesn't work?!

Including JAR as dependency and attrs.xml in res/values OR referencing the SwipeListView library as a lib dependency in your project does not work.

What works?!

Include following classes in your application package. Be sure to correct the package names in these classes to your package name

  • SwipeListView.java
  • SwipeListViewListener.java
  • SwipeListViewListenerBase.java
  • SwipeListViewTouchListener.java

Include following xml into your application res/values folder

  • attrs.xml

Now you can define and use SwipeListView as follows

<au.com.your.package.SwipeListView
        xmlns:swipe="http://schemas.android.com/apk/res-auto"
        android:id="@+id/swipe_listview"
        android:listSelector="#00000000"
        android:layout_width="match_parent"
        android:layout_height="match_parent"        
        swipe:swipeFrontView="@+id/front"
        swipe:swipeBackView="@+id/back"
        swipe:swipeActionLeft="reveal"
        swipe:swipeActionRight="choice"
        swipe:swipeMode="both"
        swipe:swipeCloseAllItemsWhenMoveList="true"
        swipe:swipeOpenOnLongPress="true"
        swipe:swipeAnimationTime="100"
        swipe:swipeOffsetLeft="50dp"
        swipe:swipeDrawableChecked="@drawable/item_selected"
        swipe:swipeDrawableUnchecked="@drawable/item_unselected"
   />

Activity code you can use same as displayed in the example on SwipeListView github site.

You will need to correct some imports from the code above. In addition, you'll need to have NineOldAndroids by Jake Wharton included as a lib dependency in your project.

The simplest test is to copy the whole thing inside your project. I see that it only has attr.xml in resources so it wont be that hard to do nor it will make your project dirty. Try that. Just copy/paste straight to /src

This should be a Android Library project and you should attach it as such. The bug you are having sometimes happens for some stupid reason which i don't know when you add libraries inside /libs (doesn't need referencing in BuildPath that way).

In this specific case this project will work only if you connect it as a library project, not a JAR.

Hope this helps.

Also this library is a Maven project. you need to have maven for android setup to be able to build it. or convert it back to a regular project.

After referencing all the libraries properly, I changed the XML to reference the SwipeListView like this:

 <main.java.com.fortysevendeg.android.swipelistview.SwipeListView
      xmlns:swipe="http://schemas.android.com/apk/res-auto"
      android:id="@+id/example_lv_list"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:listSelector="#00000000"
      swipe:swipeActionLeft="reveal"
      swipe:swipeActionRight="reveal"
      swipe:swipeAnimationTime="10"
      swipe:swipeBackView="@+id/back"
      swipe:swipeCloseAllItemsWhenMoveList="true"
      swipe:swipeFrontView="@+id/front"
      swipe:swipeMode="right"
      swipe:swipeOffsetLeft="80dip"
      swipe:swipeOffsetRight="80dip"
      swipe:swipeOpenOnLongPress="false" />

Try to add the following to build.grandle

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
    maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
}
Leonardo Costa

I had this same problem.

java.lang.ClassNotFoundException: Didn't find class "com.fortysevendeg.android.swipelistview.SwipeListView"

To solve this you need import the library in Properties > Android > Library > Add... The solution of GDroid didn't work for me.

Tip 1: Copy the library to same workspace or folder of your project, the eclipse was with problem to import the project library in other folder. This post helped me to solve this problem: https://stackoverflow.com/a/5167294/2554730

Tip 2: If you're looking for project library to ecplise, because the project to Android Studio does not works, then try open the project library in Android Studio, after finish the operations you must go at the project's folder and look for

gen-external-apklibs > com.fortysevendeg.android_swipelistview_1.0-20130701.103547-12

This is the folder with the project for eclipse. Import this project and then paste into the folder libs (if there isn't libs folder... create one) the

android-support-v4.jar and nineoldandroids-2.4.0.jar

These .jars should fix your errors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!