Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with ArrayAdapter and event onTouch #414

Open
michferrero opened this issue Sep 6, 2022 · 0 comments
Open

Problem with ArrayAdapter and event onTouch #414

michferrero opened this issue Sep 6, 2022 · 0 comments

Comments

@michferrero
Copy link

Hi, I have a problem with using the ArrayAdapter and the onTouch event in my Android application.
I would need that when pressing a button contained in the displayed row, the list is updated without losing the onTouch event.

This is my code:

public class SlotsItemAdapter extends ArrayAdapter<SlotItem>  {
private Button slotPTT = null;
...
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    ...
       slotPTT.setOnTouchListener(new View.OnTouchListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                  if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                       // During the pression of button I need to change the button following an external event

                  } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                      // This action is not performed, but I get the MotionEvent.ACTION_CANCEL

                  }
            }
       });
    }
}

During the pression of button slotPTT I need to change the background color following an external event.
I set the modify in the model and I call "notifyDataSetChanged" that refresh all the view called getView.
The getView metod refresh all the component and also the onTouch event causing the lost the focus and the event ActionUp don't fire.

I haven't been able to solve the problem for a few days. Do you have any ideas about it?
Thank you.

Michele

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant