Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:16:29+00:00 2026-06-18T03:16:29+00:00

What I want to do is when the user presses on a position in

  • 0

What I want to do is when the user presses on a position in the listView I want to see if they are flinging the view (throwing it away) or if they are just clicking it (calling the onClickListener())

I have everything set up for my classes but my problem lies in the fact that I can’t pass a MotionEvent inside of a listView, or I just don’t know how to.

Currently this is what I’ve got.

Is there a way to pass a MotionEvent without overriding dispatchTouchEvents()?

Main_screen_listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, final int position,
                    long arg3) {
                    //go to assignments or flashcards.
                    onTouchHandler myOnTouch = new onTouchHandler(Main_screen.this, position, classList);
                    //Right here is the problem!!!!!!!! I need to pass something other than null

                    MotionEvent ev = null;
                    listAdapter.notifyDataSetChanged();
                    classList = myOnTouch.motionHandler(ev, position, view);


                    AlertDialog.Builder alertBox = new AlertDialog.Builder(Main_screen.this);
                    alertBox.setTitle("Options")
                    .setPositiveButton("Assignments", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Intent currentAssignments = new Intent(Main_screen.this, assignments.Assignments.class);
                            currentAssignments.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            currentAssignments.putExtra("position", position);
                            startActivity(currentAssignments);
                        }
                    })
                    .setNegativeButton("FlashCards", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Intent currentFlashCards = new Intent(Main_screen.this, flashCards.FlashCard.class);
                            currentFlashCards.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            currentFlashCards.putExtra("position", position);
                            startActivity(currentFlashCards);
                        }
                    })
                    .show();
            }
        });

Here is my onTouchHandler class

 private class onTouchHandler extends View {

        private ArrayList<String> transferredList;
        public ArrayList<String> removeListItem(View rowView, final int position) {
            final Animation animation = AnimationUtils.loadAnimation(
                    Main_screen.this, android.R.anim.slide_out_right);
                rowView.startAnimation(animation);
                Handler handle = new Handler();
                handle.postDelayed(new Runnable() {
                    @SuppressLint({ "NewApi", "NewApi" })
                    @Override
                    public void run() {
                        transferredList.remove(position);
                        animation.cancel();
                    }
                }, 1000);
                return transferredList;
        }

        public ArrayList<String> motionHandler(MotionEvent event, int position, View rowView) {
            float startY;
            float stopX;
            float stopY;
            float finalX;
            float finalY;


            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                startX = event.getX();
                startY = event.getY();
                Toast.makeText(Main_screen.this, String.valueOf(startX), Toast.LENGTH_SHORT).show();
            }
            else if (event.getAction() == MotionEvent.ACTION_UP) {
                stopX = event.getX();
                stopY = event.getY();
                finalX = stopX - startX;
                if (finalX > 200) {
                    Toast.makeText(Main_screen.this, String.valueOf(finalX), Toast.LENGTH_SHORT).show();
                    transferredList = removeListItem(rowView, position);
                }
            }

            return transferredList; 
        }

        public onTouchHandler(Context context, ArrayList<String> mainListView) {
            super(context);
            transferredList = mainListView;
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:16:30+00:00Added an answer on June 18, 2026 at 3:16 am

    A better solution is to override getView() in your Adapter and then set the onTouchListener() of your returned View to what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to report Video position when user presses back button. Video is played
When a user presses the SEND(return) button I want the keyboard to retract and
I want to play one music repeatedly until user presses the toggle button off..
I want to start an activity when the user presses the space bar. My
I want to send a textarea's data when user presses shift + enter ,
I want to create a dialog which appears when user presses a button. (In
I want to create a form in which if the User presses Enter the
I have a table view that displays a list that I want the user
I want to hide keyboard when a user presses return in UITextView object in
Basically I want to do this: when the user presses a button, the application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.