1

i have already a listview with simpleCursorAdapter, and display thumbnails all video from sdcard..

now i want to expand my listview more, i want to add swipe listview with codes are programmatically without using any SwipeLibrary that are already given, i want to create my own set of codes using swipe

i want to create somthing like these http://www.youtube.com/watch?v=E0352OH488M

i want to create my own sets of codes without using others programmers library..

this is my code

public class FRAGThisWeek extends ListFragment {

    private static final String KEY_VIDEO_PATH = "AAA-1";
    private static final String KEY_VIDEO_TITLE = "AAA-2";
    private static final String KEY_VIDEO_ARTIST = "AAA-3";
    private static final String KEY_VIDEO_DURATION = "AAA-4";
    private static final String KEY_VIDEO_ID = "AAA-5";

    /* SOURCE URI FROM SDCARD */

    private static final Uri sourceUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    private static final String[] projection = { MediaStore.Video.Media._ID,
            MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE,
            MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.ARTIST,
            MediaStore.Video.Media.DURATION };
    private static final String orderBy = MediaStore.Video.Media.DATE_ADDED;

    /* THE DESIRED COLUMNS TO BE BOUND */
    private static final String[] from = { MediaStore.Video.Media.TITLE,
            MediaStore.Video.Media.ARTIST, MediaStore.Video.Media.DURATION };

    /* THE XML DEFINED VIEWS WHICH THE DATA WILL BE BOUND TO */
    private static final int[] to = { R.id.list_Title, R.id.list_Artist,
            R.id.list_Duration };

    private static Cursor videoCursor;
    private static int videoPathColumnIndex;
    private static int videoTitleColumnIndex;
    private static int videoArtistColumnIndex;
    private static int videoDurationColumnIndex;
    private static int videoIdColumnIndex;

    private static String videoPath;
    private static String videoTitle;
    private static String videoArtist;
    private static int videoDuration;
    private static int videoId;

    /* TO LUNCH PLAY.CLASS AND PUT MEDIA INFO INTO */
    private static Intent vIntent;

    /* MY CUSTOM ADAPTER */
    private static MyCustomSimpleCursorAdapter adapter;

    /* MY LISTVIEW */
    ListView lv;

    /* CUSTOM TYPE INFLATION IF NEED TO ADD MORE VIEW IN LISTVIEW XML LAYOUT */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.frag_this_week, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // CREATE CURSOR THAT WILL HOLD ALL VALUE
        videoCursor = getActivity().getContentResolver().query(sourceUri,
                projection, null, null, orderBy);

        // CREATE THE ADAPTER USING THE CURSOR POINTING TO THE
        // DESIRED DATA AS WELL AS THE LAYOUT INFORMATION
        adapter = new MyCustomSimpleCursorAdapter(getActivity(),
                R.layout.list_row_items, videoCursor, from, to);

        setListAdapter(adapter);

        // GET THE INSTANCE OF LISTVIEW for the swipeview purpose
        lv = getListView();
    }

    @Override
    /* ListView Listener */
    public void onListItemClick(ListView l, View v, int position, long id) {
        Log.d("clicked", "clicked");
    }

}
Piolo Opaw
  • 1,471
  • 2
  • 15
  • 21

3 Answers3

1

Why don't you take a look on how these libraries are made ?

You basically need:

  • an onTouchListener on each rows to detect the swipe gesture
  • an objectanimator to move your views.
  • a custom adapter to display your views.
Arnaud
  • 509
  • 5
  • 13
  • i have already a customcursor adapter for views, what i dont know is how to do the onTouchListerner for each row and i dont know also how to used objectanimator to move the views.. can you give me example how to do the no1 and no2 sugestion? – Piolo Opaw Dec 19 '13 at 02:29
  • Well, if you don't know how to do it.. you should better implement an existing library ! You will need **a lot** of work to achieve it. For swipe detection with an onTouchListener : [See here](http://stackoverflow.com/a/12938787/3112836) For the objectanimator, use this code when your swipe is detected : `ObjectAnimator oa = ObjectAnimator.ofFloat(view, "translationX", 0, 100f); oa.setDuration(1000); oa.start();` – Arnaud Dec 19 '13 at 11:38
  • i already implementd the 3, its working already with swipe the listview row, i put touchlistener in the getview in my custom simplecursoradapter, THANKS! PROBLEM2: if i want to put also onclicklistener for changing of activity purpose its ok to have ontouch and onclick side by side and no issues? – Piolo Opaw Jan 10 '14 at 06:56
0

I made this by adding HorizontalScrollView. Whole listview item layout is inside HorizontalScrollView. After that i implemented my own OnTouchListener for this HorizontalScrollView. Works fine without any libs.

0

Better try swipe to delete style. It suits for android. https://github.com/timroes/SwipeToDismissUndoList

Deniz
  • 12,332
  • 10
  • 44
  • 62
  • my teamLead said that if swipe there should be a 3 button should apear, delete, download, share fb.. deniz do you know some in github also? – Piolo Opaw Dec 19 '13 at 02:27