TextView and ProgressBar do not show Android data

1

I have checked the data that must show are true by means of a toast that prints them, but when wanting to show in the TextView (lessons_count) the original data does not do it, even if I put it to show a Hello. but where I update progress_general if it does.

the value of number is 1.

Code:

@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>'
    
asked by Ludwingamd 18.06.2017 в 09:22
source

2 answers

0

What I see, is that you are assigning twice a value to lecciones_count , but taking into account that I do not know if the variables are empty or not, I do not know if the "problem" could come from what I mention, I put your code with the changes:

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);
}

The changes that I have made are in the last lines; you declare the TextView ejercicios_count and the ProgressBar ejercicios_bar , but just below, you assign the value to lecciones_count and lecciones_bar ,

    
answered by 19.06.2017 в 15:32
0

First check the sequence of TextView lessons_count, first get the reference, assign a value by setText() and then change the value again by 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));
  

the original data does not do it, even if it shows you a Hello.

actually if you make the change but then overwrite it, in this line of code:

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

As for the TextView progreso_general , you define the text but it is not modified later, for this reason you do not see any problem.

TextView progreso_general = (TextView)v.findViewById(R.id.General_Count);
...
...
progreso_general.setText(String.valueOf(c)+" %");
    
answered by 19.06.2017 в 18:42