sobre sirve qué que plataforma para medio informacion comunicacion como caracteristicas antecedentes android android-listview onlongclicklistener

android - sirve - cómo implementar un oyente de clic largo en una vista de lista



youtube como medio de comunicacion pdf (7)

Creo que este código anterior funcionará en LongClicking the listview, no en los elementos individuales.

¿por qué no usar registerForContextMenu(listView) ? y luego obtener la devolución de llamada en OnCreateContextMenu.

Para la mayoría de los casos de uso, esto funcionará igual.

Quiero agregar OnLongClickListener en mi vista de lista. Cada vez que el usuario presiona el elemento en la lista, se debe realizar alguna acción, pero mi código no capta a este oyente. Por favor, hágame saber dónde me estoy equivocando. El código similar funciona para setOnItemClickListener muy bien.

Aquí está el código:

listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View v, int index, long arg3) { // TODO Auto-generated method stub Log.d("in onLongClick"); String str=listView.getItemAtPosition(index).toString(); Log.d("long click : " +str); return true; } });


En xml agregar

<ListView android:longClickable="true">

En archivo java

lv.setLongClickable(true)

prueba esto setOnItemLongClickListener ()

lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int pos, long l) { //final String category = "Position at : "+pos; final String category = ((TextView) view.findViewById(R.id.textView)).getText().toString(); Toast.makeText(getActivity(),""+category,Toast.LENGTH_LONG).show(); args = new Bundle(); args.putString("category", category); return false; } });


Esto debería funcionar

ListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) { // TODO Auto-generated method stub Toast.makeText(getContext(), "long clicked, "+"pos: " + pos, Toast.LENGTH_LONG).show(); return true; } });

Además, no lo olvide en su xml android:longClickable="true" o si tiene una vista personalizada, agregue esto a su clase de vista personalizada youCustomView.setLongClickable(true);

aquí está el resultado del código anterior


Intenté la mayoría de estas respuestas y todas fallaban en TextViews que tenían habilitado el enlace automático, pero también tenían que presionar prolongadamente en el mismo lugar.

Hice una clase personalizada que funciona.

public class TextViewLinkLongPressUrl extends TextView { private boolean isLongClick = false; public TextViewLinkLongPressUrl(Context context) { super(context); } public TextViewLinkLongPressUrl(Context context, AttributeSet attrs) { super(context, attrs); } public TextViewLinkLongPressUrl(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void setText(CharSequence text, BufferType type) { super.setText(text, type); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && isLongClick) { isLongClick = false; return false; } if (event.getAction() == MotionEvent.ACTION_UP) { isLongClick = false; } if (event.getAction() == MotionEvent.ACTION_DOWN) { isLongClick = false; } return super.onTouchEvent(event); } @Override public boolean performLongClick() { isLongClick = true; return super.performLongClick(); } }


Si su elemento de la fila ListView se refiere a un archivo XML separado, asegúrese de agregar android:longClickable="true" a ese archivo de diseño, además de establecer setOnItemLongClickListener() en su ListView.


Tienes que establecer setOnItemLongClickListener () en el ListView:

lv.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) { // TODO Auto-generated method stub Log.v("long clicked","pos: " + pos); return true; } });

El XML para cada elemento de la lista (si usa un XML personalizado) debe tener android:longClickable="true" también (o puede usar el método de conveniencia lv.setLongClickable(true); ). De esta forma, puede tener una lista con solo algunos elementos que responden a longclick.

Espero que esto te ayudará.


o prueba este código:

listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View v, int index, long arg3) { Toast.makeText(list.this,myList.getItemAtPosition(index).toString(), Toast.LENGTH_LONG).show(); return false; } });