I have an order app, I can load all the order products, since the setOnClickListener
of listview
did not work, put a setOnClick listener
in the view of the adapter, but when I show a alerdialog
it closes me the activity, I click on an item in the listview it shows me the alerdialog, when I want to click on another item it closes.
I put the code for my Adapter.
public class ProductosPedidoAdapter extends CursorAdapter{
TextView codigo, descripcion,cantidad,promocion;
AlertDialog.Builder builder;
public ProductosPedidoAdapter(Context context, Cursor c) {
super(context, c, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
return inflater.inflate(R.layout.item_producto_pedido, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
try{
builder = new AlertDialog.Builder(context);
final TextView textomostrar = new TextView(context);
codigo=(TextView) view.findViewById(R.id.text_productoCodigo_ped);
descripcion=(TextView) view.findViewById(R.id.text_descripcion_ped);
cantidad=(TextView) view.findViewById(R.id.text_cantidad_ped);
promocion=(TextView)view.findViewById((R.id.text_promocion_ped));
String codproducto=cursor.getString(cursor.getColumnIndex(contracts.detallePedido.DPcodproducto));
codigo.setText(codproducto);
descripcion.setText(cursor.getString(cursor.getColumnIndex(contracts.detallePedido.DPcodproducto)));
cantidad.setText(cursor.getString(cursor.getColumnIndex(contracts.detallePedido.DPcantidad)));
promocion.setText(cursor.getString(cursor.getColumnIndex(contracts.detallePedido.DPpromocion)));
textomostrar.setText("Que desea realizar con el producto: "+codproducto);
builder.setView(textomostrar).setTitle("Acciones");
builder.setPositiveButton("Eliminar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNeutralButton("Actualizar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
builder.show();
}
});
}catch (Exception e){
Log.e("adapterpropedidos", "bindView: ",e );
}
}
}
The catch does not catch anything.
UPDATE
This shows me the log
05-19 15:25:14.576 17647-17647/? I/art: Late-enabling -Xcheck:jni
05-19 15:25:14.576 17647-17647/? I/art: Reinit property: dalvik.vm.checkjni= false
05-19 15:25:14.594 17647-17654/? E/art: Failed sending reply to debugger: Broken pipe
05-19 15:25:14.594 17647-17654/? I/art: Debugger is no longer active
05-19 15:25:14.594 17647-17654/? I/art: Starting a blocking GC Instrumentation
05-19 15:25:14.700 17647-17647/? W/System: ClassLoader referenced unknown path: /data/app/com.cspm.ventas6.cspm-2/lib/arm64
05-19 15:25:14.701 17647-17647/? W/art: JIT profile information will not be recorded: profile file does not exits.
05-19 15:25:14.707 17647-17647/? I/InstantRun: starting instant run server: is main process
05-19 15:25:14.725 17647-17647/? I/HwCust: Constructor found for class android.app.HwCustActivityImpl
05-19 15:25:14.736 17647-17647/? I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
05-19 15:25:14.748 17647-17647/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-19 15:25:14.825 17647-17670/? I/loadProductos: codCabecera cp50587283
05-19 15:25:14.831 17647-17647/? I/HwSecImmHelper: mSecurityInputMethodService is null
05-19 15:25:14.834 17647-17647/? I/HwPointEventFilter: support AFT
05-19 15:25:14.842 17647-17647/? I/HwPointEventFilter: support AFT
05-19 15:25:14.844 17647-17647/? I/HwPointEventFilter: support AFT
05-19 15:25:14.889 17647-17671/? I/OpenGLRenderer: Initialized EGL, version 1.4
05-19 15:25:14.893 17647-17671/? W/linker: /vendor/lib64/libhwuibp.so: unused DT entry: type 0xf arg 0xe3a
05-19 15:25:14.936 17647-17647/? W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
05-19 15:42:16.315 776-776/? E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-19 15:42:16.315 776-776/? E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length