How do I apply events for Touch to individual items in Android ListView?

Asked 1 years ago, Updated 1 years ago, 90 views

listview of logic on abstractions, the ontouch When that there are 10 items of the listview. The first event at 0 times, only items on the Touch down up position the How can I do?

Currently, it is as follows.


        _IA_List.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                switch (position)
                {
                    case 0 :
                        OFF_Event();
                        break;

                    case 1 :
                        break;

                    case 2 :
                        break;

                    case 3 :
                        break;

                    case 4 :
                        break;

                    case 5 :
                        break;

                    case 6 :
                        break;

                    case 7 :
                        break;

                    case 8 :
                        break;

                    case 9 :
                        break;
                }
            }
        });
 public static void OFF_Event()
    {
        _IA_List.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch(event.getAction())
                {
                    case MotionEvent.ACTION_DOWN :
                        Toast.makeText(RadarMainActivity.instance, "+++++++++++++++a", Toast.LENGTH_SHORT).show();
                        break;

                    case MotionEvent.ACTION_UP :
                        Toast.makeText(RadarMainActivity.instance, "+++++++++++++++b", Toast.LENGTH_SHORT).show();
                        break;

                }
                return false;
            }
        });
    }

I've done it like this now, and the rest of the ListView items also bring up the same event.

The last thing I'm going to do is

I want to include the event when I press down on the item in the first ListView. While the other members are not touching the first item, they bring an event I want to stop the event when I hit my hand.

android listview touch-event

2022-09-22 15:01

1 Answers

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

I think you can register an event listener in the view that came over as a parameter Hand over the view to the OFF_Event as a parameter

OFF_Event(View view);

view.setOnTouchListener{}Try this. If I do this, I think I will register a listener only for the VIew among the many items in the list view.

_IA_List.setOnTouchListener This is like registering a TouchListener across the listener.


2022-09-22 15:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.