Click and hold the Button / Listview

1

How do I program to click and hold down a method other than just a normal click?

I would like tips, tutorials something that can help me.

I'm having a new problem I need to use the OnItemClick method and the onItemLongClick method already implemented the onItemClick and I'm in doubt how to implement the

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(getActivity().getBaseContext(), inalcancaveis_tela.class);
        startActivity(intent);}

I call this method in onCreateView

list.setOnItemClickListener(this);

OBS: to using extends Fragment

    
asked by anonymous 05.05.2014 / 14:07

3 answers

10

If you used the View.OnClickListener interface to define an action for the button (using the setOnClickListener method), you can use OnLongClickListener as well.

View.OnLongClickListener() might help implement this listener.

View view = ...;

view.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        //....
    }
});

It is important to return true if you handled the event, returning false will allow the Click event to be called.

    
05.05.2014 / 14:21
3
Button myButton = (Button) rootView.findViewById(R.id.button);
myButton.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
        System.out.println("Clique simples");
     }
     });

myButton.setOnLongClickListener(new View.OnLongClickListener() {
     @Override
     public boolean onLongClick(View v) {
        System.out.println("Clique longo");
        return false;
     }
     });
    
05.05.2014 / 14:23
1

All subclasses of View ( TextView s, ImageView s, etc.) have a setOnLongClickListener() method that receives as a parameter a View.OnLongClickListener implementation. Now just look for examples on Google.

In the particular case of item lists ( ListView s), if you want to apply the long click to an item in the list, you should call setOnItemClickListener() , which receives an implementation of AdapterView.OnItemClickListener .     

05.05.2014 / 14:19