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

  • Home
  • SEARCH
  • 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 6116313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:11:32+00:00 2026-05-23T15:11:32+00:00

My activity implements OnTouchListener and it have one ListView inside it. When user touch

  • 0

My activity implements OnTouchListener and it have one ListView inside it.
When user touch over ListView, I need to dispatch ClickEvent to ListView that has OnItemClickListener handler.

How can I do this?

edit:

Each list item of listView have onTouchEvent handler.
ListView have onItemClick handler.

  @Override
    public boolean onTouch(View view, MotionEvent event) {
        float actionUpX;

        switch(event.getAction()){

        case MotionEvent.ACTION_DOWN:
            actionDownX = event.getX();
            break;

        case MotionEvent.ACTION_UP:
            actionUpX = event.getX();

            mFlipper = (ViewFlipper) view.findViewById(R.id.view_listitem_flipper);


            if(actionDownX < actionUpX){
                // |--->
                mFlipper.showNext();                
            } else if(actionDownX > actionUpX){
                // <---|
                mFlipper.showPrevious();
            } else {
                    //Click
                    //Need to dispatch itemClickEvent to ListView

                    //view.performClick();  this line causes StackOverflowException 
                    }
            break;
        }
        return true;
    }

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
    //Need do an action using position of view

}

My list item is a ViewFlipper, when user touch and drag item, ViewFlipper need perform
showNext or ShowPrevious and an single click have to handled by onItemClick

  • 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-05-23T15:11:33+00:00Added an answer on May 23, 2026 at 3:11 pm

    If you want to be able to click on an item in the list and have something happen you need to do something like the following:

    public class YourClass extends ListActivity {
        //Your Variables
        ArrayList<Type> yourlist;
        YourAdapterClass adapter;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            yourlist = new ArrayList<Type>();
            this.adapter = new YourAdapterClass(this, R.layout.row, yourlist);
            setListAdapter(this.adapter);
    
            //you might be able to see if the below works instead of overriding 
            //the OnListItemClickListener farther below
            ListView lv = getListView();
    
            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Log.i("testy", "I Clicked on Row " + position + " and it worked!");
                 }
             });
        }
    
        @Override
        /**
         * When the user selects an item in the list, do an action
         * @param ListView l
         * @param View v
         * @param int position
         * @param long id
         */
        protected void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
    
            final int index = position;
    
            //You can add whatever you want to happen when you click here
    
            Log.i("testy", "I Clicked on Row " + index + " and this overriding worked!");
    
        }
    
    //other methods can go here for you list
    
    
    }
    

    You will also need an adapter class (in my example my adapter class is called YourAdapterClass) You can either make this a private class in your ListActivty or a completely new class in its own Java file like the following:

    public class YourAdapterClass extends ArrayAdapter {
            protected ArrayList items;
    
            public YourAdapterClass(Context context, int textViewResourceId, ArrayList items) {
                super(context, textViewResourceId, items);
                this.items = items;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
    
                if(v == null) {
                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = vi.inflate(R.layout.row, null);
                }
    
              //do stuff to your list view row if it is a custom row with multiple 
              //components like text views, image views etc.
    
                return v;
    
    
           }
    }
    

    Usually this way is used for custom ListViews (lists with custom made rows, but you can use it for a normal view as well)

    Hope this helps you at least get started in the right direction.

    Good Luck.

    (this was an answer I basically gave for another thread similar to this one Custom ListVIew and onclick)

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

Sidebar

Related Questions

I have an activity that has a TabHost containing a set of TabSpecs each
Inside public class IAmHere extends Activity implements LocationListener { i have @Override public void
I have created a custom listview that have one webview per element. My problem
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
i have public class ExperimentAllInOneActivity extends Activity implements OnClickListener on each button click listener
I have this code: public class VoiceActivity extends Activity implements OnClickListener { private TextView
I have the following code in Main.java : public class Main extends Activity implements
My activity implements KeyListener and my edittext has a key listener set. editor =
I impleme public class TextViewer extends Activity implements OnTouchListener and tv.setOnLongClickListener(itemLongClickHandler); tv.setOnTouchListener(this); But I
I have an android app that is setup to start a Java activity (call

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.