RecycleView中的EditText汇总了editText中的所有值

时间:2016-03-15 13:59:07

标签: android

我是android新手,我有两个活动,每个活动都包含一个循环视图。现在,当我点击我的第一个活动项目时,这将转到新活动并从第二个回收视图中获取结果,我需要在我的第一个回收视图中显示这个,我已经完成了所有这些,但我无法得到第二个回收视图的价值。我怎么能这样做?

这是我的代码的一部分

  holder.mGroup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent individual = new Intent(Context, `enter code here`A.class);`enter code here`
            individual.putExtra(Constants.REQ_TYPE,mCollectionDate);
            individual.putExtra(Constants.GROUP_POSITION,position);
            individual.putExtra(Constants.CENTER_POSITION,Selectedposition);
            individual.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            ((Activity)mContext).startActivityForResult(individual, 200);
            //mContext.startActivity(individual);

        }
    });
}  

谢谢!

1 个答案:

答案 0 :(得分:0)

您必须在返回之前在第二个活动上设置结果:

Intent intent = new Intent();
intent.putExtra("parameter", response);
setResult(Activity.RESULT_OK, intent);
finish();

然后对第一项活动进行处理:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if ( requestCode == 200 && resultCode == Activity.RESULT_OK ) {
        <<YOUR PARAMETER>>  =  data.getExtra("parameter");

    }
}

公共类ApplicantDetailsAdapter扩展了RecyclerView.Adapter {

Context mContext;
String mCollectionDate;
public DemandSheetModel.DemandSheetResponse demandSheetResponse;
int selectedCenter,selectedGroup;

SingletonConfig instance = SingletonConfig.getInstance();

public ApplicantDetailsAdapter(DemandSheetModel.DemandSheetResponse response,Context context,String date,int group,int center){
    if(response == null){
        throw new IllegalArgumentException("List data must not be null");
    }

    demandSheetResponse = response;
    mContext = context;
    mCollectionDate = date;
    selectedCenter = center;
    selectedGroup = group;

}
@Override
public ApplicantViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_activity_individual_applicant,parent,false);
    return new ApplicantViewHolder(view);
}

@Override
public void onBindViewHolder(final ApplicantViewHolder holder, int position) {

    DemandSheetModel.ApplicantDemandSheet demandSheet = demandSheetResponse.centers_collections_list.get(selectedCenter).jlgs.get(selectedGroup).collection_list.get(position);
    instance.setApplicantDemandSheet(demandSheetResponse.centers_collections_list.get(selectedCenter).jlgs.get(selectedGroup).collection_list.get(position));


    holder.mIndividualTotalDemand.setText(demandSheet.total_demand);
    holder.mIndividualAdvance.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            String strAdvance = holder.mIndividualAdvance.getText().toString();
            String strpreclosureTotal = holder.mIndividualPreclosure.getText().toString();
            String strTotalDemand = holder.mIndividualTotalDemand.getText().toString();

            int advanceTotal = strAdvance.trim().length() != 0 ? Integer.parseInt(strAdvance) : 0;
            float f1 = Float.parseFloat(strTotalDemand);
            int totalDemand = (int) f1;

            int preclosureTotal = strpreclosureTotal.trim().length() != 0 ? Integer.parseInt(strpreclosureTotal) : 0;

            int total = advanceTotal + preclosureTotal + totalDemand;

            holder.mIndividualTotalCollection.setText(String.format("%d", total));
        }

        @Override
        public void afterTextChanged(Editable s) {


        }
    });

    holder.mIndividualPreclosure.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            String strAdvance = holder.mIndividualAdvance.getText().toString();
            String strpreclosureTotal = holder.mIndividualPreclosure.getText().toString();
            String strTotalDemand = holder.mIndividualTotalDemand.getText().toString();

            float f1 = Float.parseFloat(strTotalDemand);
            int totalDemand = (int)f1;

            int advanceTotal = strAdvance.trim().length() != 0 ? Integer.parseInt(strAdvance) : 0;
            int preclosureTotal = strpreclosureTotal.trim().length() != 0 ? Integer.parseInt(strpreclosureTotal) : 0;

            int total = advanceTotal + preclosureTotal+totalDemand;


            holder.mIndividualTotalCollection.setText(String.format("%d", total));
        }

        @Override
        public void afterTextChanged(Editable s) {


        }
    });

    holder.mIndividualPaid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                instance.getGroupDemandSheet().group_total_collection = holder.mIndividualTotalCollection.getText().toString();
                instance.getApplicantDemandSheet().individual_payment = "paid";
            }
        }
    });
    holder.mIndividualAttendence.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){
                instance.getApplicantDemandSheet().individual_attended = "present";
            }
            else {
                instance.getApplicantDemandSheet().individual_attended = "absent";
            }
        }
    });

}

@Override
public int getItemCount() {
    int size = 0;
            for (int i=0;i<demandSheetResponse.centers_collections_list.size();i++) {
                DemandSheetModel.DemandSheet adapter = demandSheetResponse.centers_collections_list.get(i);
                for(int j=0;j<adapter.jlgs.size();j++){
                    size = adapter.jlgs.get(j).collection_list.size();
        }
    }
    return size;
}

public class ApplicantViewHolder extends RecyclerView.ViewHolder {

    TextView mIndividual,mIndividualDmandPri,mIndividualDmandInt,mIndividualOverduePri,mIndividualOverdueInt,mIndividualTotalDemand,mIndividualTotalCollection;
    EditText mIndividualAdvance,mIndividualPreclosure;
    CheckBox mIndividualPaid,mIndividualAttendence;

    public ApplicantViewHolder(View itemView) {
        super(itemView);


        mIndividualTotalDemand = (TextView)itemView.findViewById(R.id.individual_total_demand);
        mIndividualAdvance = (EditText)itemView.findViewById(R.id.individual_advance);
        mIndividualTotalCollection = (TextView)itemView.findViewById(R.id.individual_advance_total_collection);
        mIndividualPaid = (CheckBox)itemView.findViewById(R.id.individual_paid_check);
        mIndividualAttendence = (CheckBox)itemView.findViewById(R.id.individual_attendance_check);
        mIndividualPreclosure = (EditText)itemView.findViewById(R.id.individual_advance_preclosure);
    }
}