0

For getting strings from strings.xml I am using this code:

tlacitko3.setText(getResources().getString(R.string.tlacitko3));

But I realize that also work this one:

tlacitko3.setText(getString(R.string.tlacitko3));

So where is difference? Or is there something bad on shorter version? Thanks

Pavel Matras
  • 329
  • 1
  • 5
  • 13

2 Answers2

0

They both does the same. If you have many. You can use below method for better coding purpose.

public final String getString(int resId) {
     return getResources().getString(resId);
 }
Supriya
  • 1,078
  • 1
  • 8
  • 16
0

There is no difference, Use as per your convenience

They are two different methods that does the same job.

I use always :

tlacitko3.setText(getResources().getString(R.string.tlacitko3));

Because its easy to remember other other similar things like setting a imageview with a drawable

imageView.setBackground(getResources().getDrawable(R.drawable.ic_launcher));
SilentKiller
  • 6,944
  • 6
  • 40
  • 75
Devrath
  • 42,072
  • 54
  • 195
  • 297