Process when you drag your hand out of the touched view (Focus, clicked, pressed)

Asked 2 years ago, Updated 2 years ago, 26 views

When I used the cellator, I don't remember there were more than focus and press, but

I don't know the exact use of focus <

In the case of a button, if you drag it with the touch and cross the range of the button at least once, the button event will be canceled (although it hasn't even started yet), I gave it to another view (I gave it to the listview itself). Non-item) runs even if you press and go beyond that range....

listview.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_UP:
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(intent);
                break;
        }
        return false;
    }
});

When I used OnClickListener, I was told to use OnItemClickListener, but I got an error, so I used OnTouchListener. Maybe it's because of this...

How do I cancel when I drag my finger out of the view...

android

2022-09-22 21:53

2 Answers

I don't know if I understand OnClickListener() does not run onClick in the onClickListener when you move the point out of the view to cancel the click (action_up). ListView can click on the item itself

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d("TEST", "position:" + position);
            }
        });

You can get the same behavior by attaching setOnItemClickListener to the listView.


2022-09-22 21:53

I think focus is the remnant of the old trackball.

When the device first came out of the HTC with the trackball, each widget could be moved to the trackball. Roll a trackball to move items on the list, etc.

If you go to the trackball like this, the widget is active without clicking or touching it. This state is in the state where state_focus is true.

Sometimes, simulators such as Android emulators and Genie Motion move with the computer's rudder key, which also uses the focus state.

The device with the trackball went extinct, and it wasn't used very well after that.

By default, the focus status is not displayed when using the touch.

(EditText uses state_focus to display the status that can be entered.)

(From what Kearney announced at the Google Developer Summit yesterday, there was a talk about the focus status, but I don't remember exactly whether it was focus on Activity or focus on Widget.)


2022-09-22 21:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.