How to implement right swipe in ListFragment with Custom Item Adapter?

Developer :

What I need is to detect the right swipe of the item and display some activity. I did prev. investigation but it not seems to obvious to catch correct solution. Please, help me.

My code is following.

public class FragmentTwo extends ListFragment  {

    public FragmentTwo() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_fragment_two, container, false);

        return view;
    }

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

        ListView listView = getListView();

        listView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() == MotionEvent.ACTION_UP){

                    Toast.makeText(getContext(),"ACTION_UP", Toast.LENGTH_SHORT).show();
                    return true;
                }

                if(event.getAction() == MotionEvent.ACTION_DOWN){

                    Toast.makeText(getContext(),"ACTION_DOWN", Toast.LENGTH_SHORT).show();
                    return true;
                }

                if(event.getAction() == MotionEvent.ACTION_MOVE){

                    Toast.makeText(getContext(),"ACTION_MOVE", Toast.LENGTH_SHORT).show();
                    return true;
                }

                return false;
            }
        });

        new FetchTransportData().execute();

    }

    private class FetchTransportData extends AsyncTask<Void, Void, String> {
        @Override
        protected String doInBackground(Void... params) {      

                    // ...
                    return result;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
               // ...  
              CustomListAdapter adapter = new CustomListAdapter(getActivity(), unitViews);
               setListAdapter(adapter); 
        }
    }
}
Jyubin Patel :

Hi please follow the below link and this is working perfectly and i already try it and after to tell you used below link and follow it.

https://github.com/daimajia/AndroidSwipeLayout

Hope this works for you and save your time. if it's working fine please close this questions and up-vote it.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=466893&siteId=1