RecyclerView 中的预取文本布局,无法解析方法 setTextFuture
Prefetch Text Layout in RecyclerView, cannot resolve method setTextFuture
我正在尝试将预取文本布局添加到我的 reyclerview
,如图 here and here 所示。奇怪的是,它只适用于我的自定义 TextView
而不是标准 TextViews
。对于我的标准 TextView,我收到 Cannot resolve method setTextFuture
错误。
还要补充一点,之前一切正常。标准 setText
方法适用于自定义或常规 TextView
。我总共有四 (4) 个 TextView,并且所有 return 都出现相同的错误。我将其中一个转换为自定义 TextView(即使它不是)并且错误消失了。
这是我清理过的代码。
@Override
public void onBindViewHolder(@NonNull RecyclerViewHolder rvh, int position){
rvh.setMtbCard(listFiltered_main.get(position));
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public TextView tv_name;
public LengthTextView tv_length;
public RecyclerViewHolder(final View itemView, final int viewType){
super(itemView);
tv_name =itemView.findViewById(R.id.tv_name);
tv_length =itemView.findViewById(R.id.tv_length);
public void setMtbCard(final TrailsObject trailsObject) {
//not working... getting "Cannot resolve method setTextFuture" error
tv_name.setTextFuture(PrecomputedTextCompat.getTextFuture(
trailsObject.getName_diff(),
tv_name.getTextMetricsParamsCompat(),
null)
);
//seemingly works fine
tv_length.setTextFuture(PrecomputedTextCompat.getTextFuture(
trailsObject.getLength_mi(),
tv_length.getTextMetricsParamsCompat(),
null)
);
}
}
使用AppCompatTextView
代替TextView
XML
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_id"
/>
在适配器中
import android.support.v7.widget.AppCompatTextView;
public void onBindViewHolder(@NonNull RecyclerViewHolder rvh, int position){
rvh.tv.setTextFuture(PrecomputedTextCompat.getTextFuture(
string_text,
tv.getTextMetricsParamsCompat(),
null) //or your executor
);
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public final AppCompatTextView tv;
public RecyclerViewHolder(final View itemView, final int viewType){
super(itemView);
tv =itemView.findViewById(R.id.tv_id);
//......
}
}
我正在尝试将预取文本布局添加到我的 reyclerview
,如图 here and here 所示。奇怪的是,它只适用于我的自定义 TextView
而不是标准 TextViews
。对于我的标准 TextView,我收到 Cannot resolve method setTextFuture
错误。
还要补充一点,之前一切正常。标准 setText
方法适用于自定义或常规 TextView
。我总共有四 (4) 个 TextView,并且所有 return 都出现相同的错误。我将其中一个转换为自定义 TextView(即使它不是)并且错误消失了。
这是我清理过的代码。
@Override
public void onBindViewHolder(@NonNull RecyclerViewHolder rvh, int position){
rvh.setMtbCard(listFiltered_main.get(position));
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public TextView tv_name;
public LengthTextView tv_length;
public RecyclerViewHolder(final View itemView, final int viewType){
super(itemView);
tv_name =itemView.findViewById(R.id.tv_name);
tv_length =itemView.findViewById(R.id.tv_length);
public void setMtbCard(final TrailsObject trailsObject) {
//not working... getting "Cannot resolve method setTextFuture" error
tv_name.setTextFuture(PrecomputedTextCompat.getTextFuture(
trailsObject.getName_diff(),
tv_name.getTextMetricsParamsCompat(),
null)
);
//seemingly works fine
tv_length.setTextFuture(PrecomputedTextCompat.getTextFuture(
trailsObject.getLength_mi(),
tv_length.getTextMetricsParamsCompat(),
null)
);
}
}
使用AppCompatTextView
代替TextView
XML
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_id"
/>
在适配器中
import android.support.v7.widget.AppCompatTextView;
public void onBindViewHolder(@NonNull RecyclerViewHolder rvh, int position){
rvh.tv.setTextFuture(PrecomputedTextCompat.getTextFuture(
string_text,
tv.getTextMetricsParamsCompat(),
null) //or your executor
);
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public final AppCompatTextView tv;
public RecyclerViewHolder(final View itemView, final int viewType){
super(itemView);
tv =itemView.findViewById(R.id.tv_id);
//......
}
}