Click and hold on Listview

Asked

Viewed 923 times

1

As I program to click and hold down call a method other than just a normal click in Listview?

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

@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 on onCreateView

list.setOnItemClickListener(this);

NOTE: to using extends Fragment

1 answer

3


Make your class implement the event to long click implements OnItemLongClickListener And use the method onItemLongClick as below:

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

in the onCreate of your class you must now call this method to register your event:

list.setOnItemLongClickListener(this);

Abs

  • Thanks, if I need to use onItemClick would have how? and how could I implement it?

  • 1

    Hi Guilherme to use onItemClick in conjunction with onItemLongClick just implement the Onitemclicklistener event and make the call to register: list.setOnItemClickListener(this); will be two separate methods, each treating a different event.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.