Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number formatting does not take into account locale settings. Consider using String.format instead android studio

Here is my question and its solution regarding this problem..

Em trying to pass textview value between different activities, and em getting a problem. when i execute the code, the app crashes on opening StudentActivity, but then it shows the correct result..here is the code

LoginActivity.java

    int a = Integer.parseInt(textView.getText().toString());
    Intent i = new Intent(LoginActivity.this, StudentActivity.class);
    i.putExtra("level", a);
    startActivity(i);

StudentActivity.java

      textView.setText(Integer.toString(getIntent().getExtras().getInt("level")));

IN studentActivity, Integer.toString(getIntent().getExtras().getInt("level")) => this line says Number formatting does not take into account locale settings. Consider using String.format instead.Please suggest some code.. Any help would be truely appreciated!!

like image 209
Princes Aish Avatar asked Oct 10 '15 07:10

Princes Aish


1 Answers

Regarding the warning :

"Number formatting does not take into account locale settings. Consider using String.format instead android studio",

This is a Lint warning called "TextView Internationalization" which says :

When calling TextView#setText * Never call Number#toString() to format numbers; it will not handle fraction separators and locale-specific digits properly. Consider using String#format with proper format specifications (%d or %f) instead.

So you should have written :

 textView.setText(String.format("%d", getIntent().getExtras().getInt("level"))));
like image 94
Nicolas Bossard Avatar answered Sep 22 '22 11:09

Nicolas Bossard