2

Bueno Básicamente tengo el siguiente inconveniente. Tengo un ReciclerView que contiene varios EditText y va actualizando conforme cambia el texto y cuando se le requiera retornara la lista de items.

A su vez esto se hace desde un AlertDialog, ya que necesito que sea llamado desde una ventana emergente y no desde otro fragment

La primera parte es simple, pero mi problema reside en que el teclado no es llamado cuando se enfoca en el EditText, Ademas de que hint de este tampoco se muestra, he hecho pruebas y he concluido que el detalle es el uso del AlertDialog

Código del Adapter

public class AdRestos extends RecyclerView.Adapter<AdRestos.HolderPerdidas> {
    private List<Restos> mitems;
    private Runas1 runas1;
    private TextView estimatedConsequences;

    public AdRestos(List<Restos> mitems, Runas1 runas1, final TextView estimatedConsequences) {
        this.mitems = mitems;
        this.runas1 = runas1;
        this.estimatedConsequences = estimatedConsequences;
    }

    @NonNull
    @Override
    public AdRestos.HolderPerdidas onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
        LayoutInflater layoutInflater=LayoutInflater.from(viewGroup.getContext());
        View view = layoutInflater.inflate(R.layout.item_caracteristicas_afectadas,viewGroup,false);
        return new HolderPerdidas(view);
    }


    @Override
    public void onBindViewHolder(@NonNull final AdRestos.HolderPerdidas holder, final int position) {

        holder.txtNombre.setText(mitems.get(position).getNombre());

        //Coloco el valor antes de crear agregar lo escuchas
        if(mitems.get(position).getCantidad() <0 || mitems.get(position).getCantidad()>0){
           holder.edtValue.setText(mitems.get(position).getCantidad()+"");
        }else{
            holder.edtValue.setText("");
        }

        holder.edtValue.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                try{
                    mitems.get(position).setCantidad(Integer.parseInt(s.toString()));
                }catch (Exception e){
                    mitems.get(position).setCantidad(0);
                }

                Log.e("Posición",position+"");
                Log.e("Valor Campo",holder.edtValue.getText().toString());
                Log.e("Valor Lista",mitems.get(position).getCantidad()+"");

                try{
                    Log.e("Valor Hint",holder.edtValue.getHint().toString());
                }catch (Exception e){
                    Log.e("Error HINT",e.getMessage());
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        //Prueba para ver si tiene focus

        holder.edtValue.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    Log.e("FOCUS...","SI");
                }else{
                    Log.e("FOCUS...","NO");
                }

            }
        });


    }

    @Override
    public int getItemCount() {
        if(mitems !=null)
            return mitems.size();
        return 0;
    }

    public List<Restos> getAll(){
        return mitems;
    }


    public class HolderPerdidas extends RecyclerView.ViewHolder {
        public TextView txtNombre;
        public EditText edtValue;

        public HolderPerdidas(@NonNull View itemView) {
            super(itemView);
            txtNombre= (TextView) itemView.findViewById(R.id.txt_caracteristica);
            edtValue= (EditText) itemView.findViewById(R.id.edt_value);
        }
    }
}

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/txt_caracteristica"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="16dp"
        android:textAlignment="textEnd"
        android:textSize="14sp"
        app:layout_constraintBottom_toBottomOf="@+id/edt_value"
        app:layout_constraintEnd_toStartOf="@+id/edt_value"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/edt_value"
        tools:text="Fuerza" />

    <EditText
        android:id="@+id/edt_value"
        android:layout_width="45dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="4dp"
        android:hint="0"
        tools:text="20"
        android:inputType="number|numberSigned"
        android:textAlignment="center"
        android:textColorHint="#FF0000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

</android.support.constraint.ConstraintLayout>

Llamada del AlertDialog

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

                LayoutInflater inflater = getActivity().getLayoutInflater();

                View dialogView= inflater.inflate(R.layout.dialog_restos, null);



                builder.setTitle(resources.getString(R.string.rest_title));
                builder.setMessage(resources.getString(R.string.rest_message));

                Switch allowRest;
                RecyclerView rvRest;
                TextView estimatedConsequences;

                allowRest = (Switch) dialogView.findViewById(R.id.rest_affected);
                estimatedConsequences = (TextView) dialogView.findViewById(R.id.txt_estimated);
                rvRest = (RecyclerView) dialogView.findViewById(R.id.rv_affected_data);
                rvRest.setLayoutManager(new LinearLayoutManager(context));

                AdRestos adRestos = new AdRestos(restosList,runas1,estimatedConsequences);
                rvRest.setAdapter(adRestos);
                rvRest.setItemViewCacheSize(100);

                builder.setView(dialogView);

                AlertDialog dialog = builder.create();
                dialog.show;

LOGCAT

2018-11-11 02:18:22.055 22629-22629/xx.xxxxxxxx.xxxxx E/FOCUS...: SI
2018-11-11 02:18:24.601 1387-1617/? E/audio_hw_generic: pcm_write failed cannot write stream data: I/O error
2018-11-11 02:18:34.609 1387-1617/? E/audio_hw_generic: pcm_write failed cannot write stream data: I/O error
2018-11-11 02:18:52.014 22629-22629/xx.xxxxxxxx.xxxxx E/Posición: 0
2018-11-11 02:18:52.014 22629-22629/xx.xxxxxxxx.xxxxx E/Valor Campo: 2
2018-11-11 02:18:52.014 22629-22629/xx.xxxxxxxx.xxxxx E/Valor Lista: 2
2018-11-11 02:18:52.014 22629-22629/xx.xxxxxxxx.xxxxx E/Error HINT: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
2018-11-11 02:19:35.177 1776-1803/? E/memtrack: Couldn't load memtrack module

Imagen del dialogo

Imagen del Dialog

Lo curioso es que el hint y el la aliniacion es omitida dentro del dialog

Imagen de la vista

El Recycler omite info

Uso un codigo muy similar pero mucho mas cargado y funciona perfectamente pero claro este lo ejecuto desde un fragment y no dentro de un dialogo

Agradecería muchísimo me ayuden a ver mi error y como poder solucionarlo

3
  • Prueba a hacer builder.show() en vez de AlertDialog dialog = builder.create(); dialog.show; y otra cosa... no tendrás ocultado el teclado sobre esta actividad en el manifest? Commented el 21 nov. 2018 a las 13:43
  • no funciona y no ya que se muestra se muestra si hago focus en algun textview de atras los cuales estan en el fragment
    – Darkeniel
    Commented el 22 nov. 2018 a las 3:57
  • Prueba con AlertDialog.Builder b = new AlertDialog.Builder(getApplicationContext());//.... AlertDialog dialog = b.create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); Commented el 22 nov. 2018 a las 6:43

1 respuesta 1

-2

Intenta cambiar el AlertDialog por DialogFragment

Ejemplo:

// Instanciar el fragment

FragmentTransaction ft = getFragmentManager().beginTransaction();
DialogFragment newFragment = new MyDialogFragment();
newFragment.show(ft, "dialog");

// Código del fragment

public static class MyDialogFragment extends DialogFragment {

    @Override
    public View onCreateView(LayoutInflater i, ViewGroup c, Bundle b) {
        View v = inflater.inflate(R.layout.my_dialog, container, false);
        return v;
    }
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.