samedi 7 octobre 2017

How to use OnLongPressed for a CheckBox Array list? Android Studio Java

I already know how to use MotionEvent.ACTION_DOWN See my code below.

 //set touch listener for the checkboxes.
        for(int i = 0; i < checkBoxArrayList.size(); i++){

            checkBoxArrayList.get(i).setId(i);

            checkBoxArrayList.get(i).setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {

                    switch(motionEvent.getAction()) {

                        case MotionEvent.ACTION_DOWN:

                                view.postDelayed(runnable, 0);
                                checkboxPopupCheck = view.getId();
                                Toast.makeText(MainActivity.this, changeToast(checkBoxArrayList.get(view.getId()).getText()) + "is selected.", Toast.LENGTH_SHORT).show();

                            //set check var to the checkbox that's pressed down.

                            //test for which item is selected
                            //Toast.makeText(MainActivity.this,Integer.toString(checkboxPopupCheck)+ "is selected.",Toast.LENGTH_SHORT).show();
                            break;
                    }
                    return false;
                }
            });
            }        

I need to learn how to use the gesture detection for a long pressed for my check boxes.

I have already read the documentation

http://ift.tt/1hFCXjN

But I'm not sure how to implement it for my use.

 @Override
        public void onLongPress(MotionEvent motionEvent) {
            for(int i = 0; i < checkBoxArrayList.size(); i++){

                checkBoxArrayList.get(i).setId(i);

                //motionEvent-How do i complete this?
                checkBoxArrayList.get(i).

            }

        }

I have tried using setOnGenericMotionListener but as far as I could tell it didn't have the OnLongPressed feature.




Aucun commentaire:

Enregistrer un commentaire