Firebase从多级随机ID中获取数据

时间:2017-08-01 16:31:12

标签: android firebase firebase-realtime-database

这是我的Firebase数据库设置:

Firebase database

这成功地将我的工作流程名称设置为intent i。

adapter = new FirebaseRecyclerAdapter<Workflow, WorkflowHolder>(
            Workflow.class,
            R.layout.list_row,
            WorkflowHolder.class,
            ref) {
        @Override
        public void populateViewHolder(WorkflowHolder holder, Workflow workflow, final int position) {
            holder.setName(workflow.getName());
            holder.setNextdue(workflow.getNextdue());
            holder.setLastcompleted(workflow.getLastcompleted());
            final String workflow_name = workflow.getName();

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setTitle("Begin Workflow");
                    builder.setMessage("Are you sure you are ready to begin workflow " + workflow_name + "?");
                    builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {




                            Intent i = new Intent(MainActivity.this, CompleteWorkflow.class);
                            i.putExtra("workflow_id", adapter.getRef(position).toString());
                            i.putExtra("workflow_name", workflow_name);
                            startActivity(i);
                            finish();
                            dialog.dismiss();
                        }
                    });
                    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            //TODO
                            dialog.dismiss();
                        }
                    });
                    AlertDialog dialog = builder.create();
                    dialog.show();
                }
            });
        }
    };

    workflows.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));

    workflows.setAdapter(adapter);

但是,我想要工作流的所有任务,所以基本上能够将所有任务的json放到intent i中。这有可能吗?

另外,我的Workflow.class就是这样:

public class Workflow {
private String name, lastcompleted;
private Long nextdue;

public Workflow(){
}

public Workflow(String name, Long nextdue, String lastcompleted) {
    this.name = name;
    this.nextdue = nextdue;
    this.lastcompleted = lastcompleted;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Long getNextdue() {
    return nextdue;
}

public void setNextdue(Long nextdue) {
    this.nextdue = nextdue;
}

public String getLastcompleted() {
    return lastcompleted;
}

public void setLastcompleted(String lastcompleted) {
    this.lastcompleted = lastcompleted;
}

}

关于如何重组的任何想法?

2 个答案:

答案 0 :(得分:0)

是的,这是可能的。您可以将workflow class的所有信息封装到实现workflow object的{​​{1}}中。

代码看起来与您的类似,但不是传递2个不同的附加内容,您只需传递一个,即工作流对象。假设您已在POJO类中设置了Parcelable interfacesetWorkFlowId,请使用以下代码:

setWorkFlowName

有关实施Workflow workflow = new Workflow(); workflow.setWorkFlowId(adapter.getRef(position).toString()); workflow.setWorkFlowName(workflow_name); i.putExtra("workflow, workflow); 的详情,请参阅Parcelable Offical Documentation

您也可以使用Parcelable代替Parcelable,但速度要慢得多。所以恕我直言是最简单的选择。

希望它有所帮助。

答案 1 :(得分:0)

缺乏开发人员沟通再次,任务结果是一个ArrayList。感谢大家的帮助!