如何通过卡片更新我从arraylist获得的Json?

时间:2017-05-11 10:22:08

标签: java android json android-cardview

我从Rally获得Json数据。我在ArrayList的帮助下将其设置在卡片视图中。我想修改2个值并将Json响应发送回server.How我可以实现吗??

enter image description here

这是cardview.through滑块控件我想在刷卡时更新一个值和其他值。

我的代码:

restApi=new RallyRestApi(new URI("https://rally1.rallydev.com"),username,password);
                    QueryRequest us = new QueryRequest("HierarchicalRequirement");
                    QueryFilter currentiteration = new QueryFilter("Iteration.StartDate","<=",today1);
                    currentiteration = currentiteration.and(new QueryFilter("Iteration.EndDate",">=",today1));
                    us.setQueryFilter(currentiteration);
                    us.setFetch(new Fetch("Name", "FormattedID","Tasks"));
                    JsonArray us1 = restApi.query(us).getResults();
                    for(int i=0;i<us1.size();i++)
                    {
                        QueryRequest task = new QueryRequest((JsonObject) us1.get(i).getAsJsonObject().get("Tasks"));
                        task.setFetch(new Fetch("Name","Actuals","Estimate"));
                        JsonArray tsk = restApi.query(task).getResults();
                        for(int j=0;j<tsk.size();j++)
                        {
                            MyData data = new MyData(us1.get(i).getAsJsonObject().get("Name").toString(),tsk.get(j).getAsJsonObject().get("Name").toString(),tsk.get(j).getAsJsonObject().get("Actuals").toString(),tsk.get(j).getAsJsonObject().get("Estimate").toString(),(int) Double.parseDouble(tsk.get(j).getAsJsonObject().get("Actuals").toString()),(int) Double.parseDouble(tsk.get(j).getAsJsonObject().get("Estimate").toString()));
                            //System.out.println("UserStory : "+us1.get(i).getAsJsonObject().get("Name")+"Task : "+tsk.get(j).getAsJsonObject().get("Name"));
                            data_list.add(data);
                        }
                    }

MyData是带有getter / setter的类。

自定义适配器类:

@Override
    public void onBindViewHolder(final ViewHolder holder, final int position)
    {
        holder.userstory.setText("User Story: "+my_data.get(position).getUserstory());
        holder.tasks.setText("Task: "+my_data.get(position).getTask());
        holder.seekBar.setMax(my_data.get(position).getEstimate());
        holder.seekBar.setProgress(my_data.get(position).getActual());
        holder.actual_estimate.setText(my_data.get(position).getActual()+"/"+my_data.get(position).getEstimate());
        holder.seekBar.setOnSeekBarChangeListener(new CircularSeekBar.OnCircularSeekBarChangeListener() {
            @Override
            public void onProgressChanged(CircularSeekBar circularSeekBar, int progress, boolean fromUser)
            {
                holder.actual_estimate.setText(holder.seekBar.getProgress()+"/"+my_data.get(position).getEstimate());
            }

            @Override
            public void onStopTrackingTouch(CircularSeekBar seekBar) {

            }

            @Override
            public void onStartTrackingTouch(CircularSeekBar seekBar) {

            }
        });
    }

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

    public  class ViewHolder extends  RecyclerView.ViewHolder
    {
        public TextView userstory,tasks,actual_estimate;
        public CircularSeekBar seekBar;
//
        public ViewHolder(View itemView)
        {
            super(itemView);
            userstory=(TextView) itemView.findViewById(R.id.tvUserStory);
            tasks=(TextView) itemView.findViewById(R.id.tvTask);
            seekBar=(CircularSeekBar) itemView.findViewById(R.id.circularSeekBar1);
            actual_estimate=(TextView) itemView.findViewById(R.id.tvactuals_estimate);
        }
    }

它处理卡片视图。

我想在应用中实现的代码:

JsonObject updatedValues = new JsonObject();
updatedValues.addProperty("Actuals", //value from the circularseekbar);
UpdateRequest taskUpdate = new UpdateRequest(//reference of the card, updatedValues);
restApi.update(taskUpdate);

有人可以帮忙吗?谢谢

0 个答案:

没有答案