ListView listView = findViewById(R.id.listView); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { Toast.makeText(getApplicationContext(), "ListView touched", Toast.LENGTH_SHORT).show(); return false; } });
ListView listView = findViewById(R.id.listView); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int position = listView.pointToPosition((int)event.getX(), (int)event.getY()); if (position != ListView.INVALID_POSITION) { listView.getChildAt(position - listView.getFirstVisiblePosition()).setBackgroundColor(Color.RED); } } return false; } });This example sets the OnTouchListener to the ListView and changes the background color of the selected item when the user touches the ListView. The package used is android.view.View.OnTouchListener.