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

适配器支架中的Android getString性能问题,android,getstring,Android,Getstring,我访问适配器中的字符串资源。但我有一个问题,那就是哪种方式是有用的还是更好的性能?第一种方法似乎没有用处,但它是否会在性能方面产生问题 1 Context context; public Adapter(Context context){ this.context = context; } ... ... public void onBind(Holder holder,int position) { holder.text.setText(context.getReso

我访问适配器中的字符串资源。但我有一个问题,那就是哪种方式是有用的还是更好的性能?第一种方法似乎没有用处,但它是否会在性能方面产生问题

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

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

第二种方法对性能的影响较小。可以避免多次查找字符串资源。如果没有一个合适的基准,就不能说性能会受到多大的影响

就有用性而言,两者都会起作用