Android 适配器支架中的 getString 性能问题

Android getString performance issue in adapter holder

我在适配器中访问字符串资源。但我担心哪种方式有用或性能更好?第一种方式似乎没有用,但它会在性能方面产生问题吗?

1;

Context context;
public Adapter(Context context){
     this.context = context;
}

...
...

public void onBind(Holder holder,int position) {
     holder.text.setText(context.getResources().getString(R.string.formText, position));
}

2;

Context context;
String formText;

public Adapter(Context context){
     this.context = context;
     this.formText= context.getResources().getString(R.string.formText);
}

...
...

public void onBind(Holder holder,int position) {
     holder.text.setText(String.format(formText, position));
}

第二个对性能的影响较小。您避免多次查找字符串资源。没有合适的基准,就不能说性能受到了多大影响。

就实用性而言,两者都可以。