Question

I got an autocompletetextview and i want to make an onlongclick for the list items. i tried to set an onlongclick for the actv but its set for the edittext not for the list items.

     ArrayAdapter<String> adapter = new ArrayAdapter<String>
      (this, android.R.layout.simple_list_item_1, masini);
      txtNrInmat.setAdapter(adapter);
      txtNrInmat.setLongClickable(true);

      txtNrInmat.setOnLongClickListener(new OnLongClickListener() { 
          public boolean onLongClick(View v) {
              Toast.makeText(getApplicationContext(), "Long Press works", Toast.LENGTH_SHORT).show();
              return true;
          }
      });

How can i make an onlongclick for the items inside the dropdown list?

Was it helpful?

Solution

The best way to do it I think would be to have a custom adapter.

You can for exemple extend ArrayAdapter, and in getView method, call setOnLongClickListener for each view of your adapter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top