recyclerview之间的互动

时间:2016-05-03 13:40:43

标签: java android android-recyclerview

有两个recyclerview和两个适配器。 recyclerview都包含文本字段和按钮。我在下面按下一个recyclerview项目跳转到另一个recyclerview,反之亦然。怎么做?

第一个适配器:

public class RVAdapterStart extends RecyclerView.Adapter<RVAdapterStart.TaskViewHolder> {
public static class TaskViewHolder extends RecyclerView.ViewHolder {
    RelativeLayout relativeLayout;
    private TextView title;
    private TextView status;
    private Button button;

    TaskViewHolder(View view) {
        super(view);
        relativeLayout = (RelativeLayout) view.findViewById(R.id.frameLayout);
        title = (TextView) view.findViewById(R.id.title);
        status = (TextView) view.findViewById(R.id.status);
        button = (Button) view.findViewById(R.id.tasks_finish);
    }
}

private List<Task> tasksStart;

RVAdapterStart() {

}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}

@Override
public void onBindViewHolder(TaskViewHolder holder, final int position) {
    holder.title.setText(tasksStart.get(position).getTitle());
    holder.status.setText(tasksStart.get(position).getStatus());
    holder.button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
}

@Override
public int getItemCount() {
    return tasksStart.size();
}

@Override
public TaskViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_tasks_start, viewGroup, false);
    TaskViewHolder tvh = new TaskViewHolder(view);
    return tvh;
}

第二个适配器:

public class RVAdapterProcces extends RecyclerView.Adapter<RVAdapterProcces.TasksViewHolder> {
public static class TasksViewHolder extends RecyclerView.ViewHolder {
    RelativeLayout relativeLayout;
    private TextView title;
    private TextView status;
    private Button TaskFinishBtn;
    private Button TaskCancelBtn;

    TasksViewHolder(View view) {
        super(view);
        relativeLayout = (RelativeLayout) view.findViewById(R.id.relative_tasks_procces);
        title = (TextView) view.findViewById(R.id.title_procces);
        status = (TextView) view.findViewById(R.id.status_procces);
        TaskFinishBtn = (Button) view.findViewById(R.id.tasks_finish);
        TaskCancelBtn = (Button) view.findViewById(R.id.tasks_procces_cancel);
    }
}

private List<Task> tasksProcces = new ArrayList<Task>();

RVAdapterProcces() {

}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}

@Override
public void onBindViewHolder(TasksViewHolder holder, final int position) {
    holder.title.setText(tasksProcces.get(position).getTitle());
    holder.status.setText(tasksProcces.get(position).getStatus());
}

@Override
public int getItemCount() {
    return tasksProcces.size();
}

@Override
public TasksViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_tasks_procces, viewGroup, false);
    TasksViewHolder tvh = new TasksViewHolder(view);
    return tvh;
}

0 个答案:

没有答案