2016-10-26 2 views
2

어댑터의 문자열 리소스에 액세스합니다. 그러나 나는 어느 방법으로 유용하고 더 나은 성과를 낼지 염려합니다. 첫 번째 방법은 유용하지 않지만 성능면에서 문제가 발생합니까?어댑터 보유자의 Android getString 성능 문제

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

답변

3

두 번째는 성능 저하가 적습니다. 문자열 리소스를 두 번 이상 조회하지 않아도됩니다. 적절한 벤치 마크가 없으면 얼마나 많은 성능이 영향을 받는지 말할 수 없습니다.

유용한만큼, 둘 다 작동합니다.