1

He comprobado los datos que debe mostrar son verdaderos mediante un toast que los imprime, pero al querer mostrar en el TextView (lecciones_count) el dato nteoria no lo hace, ni aunque le ponga que muestre un Hola. pero en donde actualizo progreso_general si lo hace.

el valor de nteoria es 1.

Codigo:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v;
    v = inflater.inflate(R.layout.fragment_principal, container, false);


    progreso(v);
    return v;

}

public void progreso(View v){
    TextView progreso_general = (TextView)v.findViewById(R.id.General_Count);
    ProgressBar progreso_general_bar = (ProgressBar)v.findViewById(R.id.General_bar);

    int total = totalejercicios+totalteoria;

    progreso_general.setText(String.valueOf(c)+" %");
    progreso_general_bar.setMax(total);
    progreso_general_bar.setProgress(nejercicios+nteoria);

    TextView lecciones_count = (TextView)v.findViewById(R.id.lecciones_count);
    ProgressBar lecciones_bar = (ProgressBar)v.findViewById(R.id.lecciones_bar);

    Toast toast1 = Toast.makeText(getContext(),String.valueOf(nteoria), Toast.LENGTH_SHORT);
    toast1.show();

    lecciones_count.setText(String.valueOf(nteoria).concat("/").concat(String.valueOf(totalteoria)));

    lecciones_bar.setMax(totalteoria);
    lecciones_bar.setSecondaryProgress(totalteoria);

    lecciones_bar.setProgress(nteoria);



    TextView ejercicios_count = (TextView)v.findViewById(R.id.ejercicios_count);
    ProgressBar ejercicios_bar = (ProgressBar)v.findViewById(R.id.ejercicios_bar);

    lecciones_count.setText(String.valueOf(nejercicios)+"/"+String.valueOf(totalejercicios));

    lecciones_bar.setMax(totalejercicios);
    lecciones_bar.setSecondaryProgress(totalejercicios);

    lecciones_bar.setProgress(nejercicios);
}

XML`

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="50sp"
                    android:paddingTop="15sp"
                    android:text="@string/lecciones"
                    android:textSize="26sp" />

                <TextView
                    android:id="@+id/lecciones_count"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="0/0"
                    android:textSize="32sp" />

            </LinearLayout>`

2 respuestas 2

0

Lo que veo, es que estas asignando dos veces un valor a lecciones_count, pero teniendo en cuenta que no se si las variables están o no vacias, no se si el "problema" pueda venir de lo que comento, pongo tu código con los cambios:

public void progreso(View v){
        TextView progreso_general = (TextView)v.findViewById(R.id.General_Count);
        ProgressBar progreso_general_bar = (ProgressBar)v.findViewById(R.id.General_bar);

        int total = totalejercicios+totalteoria;

        progreso_general.setText(String.valueOf(c)+" %");
        progreso_general_bar.setMax(total);
        progreso_general_bar.setProgress(nejercicios+nteoria);

        TextView lecciones_count = (TextView)v.findViewById(R.id.lecciones_count);
        ProgressBar lecciones_bar = (ProgressBar)v.findViewById(R.id.lecciones_bar);

        Toast toast1 = Toast.makeText(getContext(),String.valueOf(nteoria), Toast.LENGTH_SHORT);
        toast1.show();

        lecciones_count.setText(String.valueOf(nteoria).concat("/").concat(String.valueOf(totalteoria)));

        lecciones_bar.setMax(totalteoria);
        lecciones_bar.setSecondaryProgress(totalteoria);

        lecciones_bar.setProgress(nteoria);



        TextView ejercicios_count = (TextView)v.findViewById(R.id.ejercicios_count);
        ProgressBar ejercicios_bar = (ProgressBar)v.findViewById(R.id.ejercicios_bar);

        ejercicios_count.setText(String.valueOf(nejercicios)+"/"+String.valueOf(totalejercicios));

        ejercicios_bar.setMax(totalejercicios);
        ejercicios_bar.setSecondaryProgress(totalejercicios);

        ejercicios_bar.setProgress(nejercicios);
}

Los cambios que he realizado, son en las últimas lineas; declaras el TextView ejercicios_count y el ProgressBar ejercicios_bar, pero justo debajo, asignas el valor a lecciones_count y lecciones_bar,

0

Primeramente revisa la secuencia del TextView lecciones_count, primeramente obtiene la referencia, asigna un valor mediante setText() y posteriormente cambia el valor nuevamente mediante setText():

    TextView lecciones_count = (TextView)v.findViewById(R.id.lecciones_count);
    ...
    ...   
lecciones_count.setText(String.valueOf(nteoria).concat("/").concat(String.valueOf(totalteoria)));
    ...
    ...    
lecciones_count.setText(String.valueOf(nejercicios)+"/"+String.valueOf(totalejercicios));

el dato nteoria no lo hace, ni aunque le ponga que muestre un Hola.

en realidad si realiza el cambio pero posteriormente lo sobreescribe, en esta linea de código:

lecciones_count.setText(String.valueOf(nejercicios)+"/"+String.valueOf(totalejercicios));

En cuanto al TextView progreso_general, defines el texto pero no es modificado posteriormente, por esta razón no ves ningún problema.

TextView progreso_general = (TextView)v.findViewById(R.id.General_Count);
...
...
progreso_general.setText(String.valueOf(c)+" %");

Tu Respuesta

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

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