Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Opciones en las que se puede hacer clic en AlertDialog después de un clic largo en ListView

Estoy tratando de configurar una vista de lista con un OnItemLongClickListener(), que abrirá un cuadro de diálogo de alerta con un diseño personalizado. Luego quiero que el diseño tenga dos botones, uno para abrir otra actividad para editar la entrada en SQLite DB y otro para eliminar la entrada. Mi onItemLongClickListener() funciona y puedo abrir un diseño personalizado, pero no sé cómo cerrar el cuadro de diálogo después de hacer clic en el botón o ejecutar los métodos que quiero.

Mi ListViewItemLongClick():

 private void listViewItemLongClick(){ final ListView myList = (ListView) findViewById(R.id.resourcesList); myList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Id = id; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this); // ...Irrelevant code for customizing the buttons and title LayoutInflater inflater = getLayoutInflater(); View dialogView = inflater.inflate(R.layout.alert_layout, null); dialogBuilder.setView(dialogView); AlertDialog alertDialog = dialogBuilder.create(); alertDialog.show(); return true; } }); }

Mi diseño de alerta personalizado:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/Edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="edit" android:text="Edit" /> <Button android:id="@+id/delete" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="delete" android:text="Delete" /> </LinearLayout>

Cualquier ayuda sería muy apreciada, todavía soy muy nuevo en la programación de Android.

¡Salud!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Con mi solución, no necesita un archivo XML. Por supuesto, puede usarlo para agregar EditText, por ejemplo, y obtenerlo con EditText ed = (EditText)dialog.findViewById(R.id.dialog_get_name_ed);

Pero para tu caso, prueba esto

 dialogBuilder.setPositiveButton("Edit", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // you have your edit button } }); dialogBuilder.setNegativeButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // you have your delete button } });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!