我有一个带有以下适配器的RecyclerView
:
public class DataTransferMeasureListAdapter extends DataTransferBaseListAdapter<DataTransferMeasureListAdapter.ViewHolder> {
private Context context = null;
private List<DataTransferListEntry> entries = null;
public DataTransferMeasureListAdapter(Context context, List<DataTransferListEntry> entries) {
super(context);
this.context = context;
this.entries = entries;
}
@Override
public DataTransferMeasureListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context).inflate(R.layout.fragment_datatransfer_measure_list_row, parent, false);
return new DataTransferMeasureListAdapter.ViewHolder(this.context, itemView);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final DataTransferMeasureListEntry entry = (DataTransferMeasureListEntry) entries.get(position);
final ViewHolder viewHolder = (ViewHolder) holder;
String time = Helper.getDateTimePattern(this.context, entry.getDate());
String value = Helper.getMeasureValue(unit, entry.getValue());
viewHolder.textViewTime.setText(time);
viewHolder.textViewValue.setText(value);
}
@Override
public int getItemCount() {
return entries.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
private Context context = null;
private TextView textViewValue = null;
private TextView textViewTime = null;
public ViewHolder(Context context, View itemView) {
super(itemView);
this.context = context;
this.textViewValue = (TextView) itemView.findViewById(R.id.datatransfer_measure_list_row_textview_value);
this.textViewTime = (TextView) itemView.findViewById(R.id.datatransfer_measure_list_row_textview_time);
}
}
}
在我的
ListView
中:@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.adapter = new DataTransferMeasureListAdapter(this.getActivity(), this.dataTransferMeasureListEntries);
this.listRowParent = (RecyclerView) view.findViewById(R.id.datatransfer_measure_list_row_parent);
this.listRowParent.setAdapter(this.adapter);
this.listRowParent.setLayoutManager(new LinearLayoutManager(this.getActivity()));
}
我现在需要一种方法来迭代适配器中的每个Viewholder
,以便可以更改某些视图元素的可见性。我需要从适配器外部进行设置。
我该如何做到这一点?