我已经通过服务器的JSON响应填充了recyclerview。
recyclerview项目包括图像和时间。还有一个按钮,其可见性设置为不可见。
这是每个项目看起来如何使用按钮(也编辑)可见
现在,在(点击应用程序的)菜单项中有一个编辑按钮,我想将所有的recyclerview项目按钮设置为可见。
我怎么能实现这个目标?我试着寻找同样但无济于事。
编辑:
这是Schedule Fragment中显示RecyclerView的项目代码。
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_edit:
//onClick of edit menu item
return true;
default:
return super.onOptionsItemSelected(item);
}
}
这是ScheduleAdapter中的ViewHolder类
public class ViewHolder extends RecyclerView.ViewHolder {
private NetworkImageView imageView_status;
private TextView textView_status;
private TextView textView_time;
private Button button_edit;
public ViewHolder(View itemView) {
super(itemView);
imageView_status = (NetworkImageView) itemView.findViewById(R.id.imageView);
textView_status = (TextView) itemView.findViewById(R.id.textView_Status);
textView_time = (TextView) itemView.findViewById(R.id.textView_Time);
button_edit = (Button) itemView.findViewById(R.id.button);
}
}
这是ScheduleAdapter的onBindViewHolder
public void onBindViewHolder(final CustomScheduleListAdapter.ViewHolder holder, int position) {
if (imageLoader == null) {
imageLoader = AppController.getInstance().getImageLoader();
}
holder.imageView_status.setImageUrl(punches.get(position).getImageURL(), imageLoader);
holder.textView_status.setText(punches.get(position).getStatusName());
holder.textView_time.setText(punches.get(position).getTimings());
holder.button_edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
//Actions performed after button click
}
});
}
答案 0 :(得分:1)
您可以在适配器中有一个字段,用于跟踪onBindViewHolder
项是否应设置为可见。然后在onOptionsItemSelected
中,您可以根据它设置视图的可见性。最后在notifyItemRangeChanged
中,您可以在适配器中设置该字段的值,并在其上调用public class ScheduleAdapter extends RecyclerView.Adapter<CustomScheduleListAdapter.ViewHolder> {
private boolean showAllViews = false;
public void setShowAllViews(boolean show) {
showAllViews = show;
notifyItemRangeChanged(0, getItemCount());
}
@Override
public void onBindViewHolder(CustomScheduleListAdapter.ViewHolder holder, int position) {
holder.viewyoucareabout.setVisibility(showAllViews? View.VISIBLE : View.GONE);
}
}
。
例如:
适配器:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_edit:
adapter.setShowAllViews(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
计划片段:
CSV.open('dest.csv', 'w') do |csv|
csv << ["val1", "val2","mul"]
CSV.foreach('source.csv') do |row|
c1 = row[0]
c2 = row[1]
csv << [c1, c2, c1*c2]
end
end