根据我的图片,第二个请求的详细信息是cardviews
,只需点击添加按钮,当我点击 editImageButton
时,所有textview
值将再次放在第一个请求详细信息的edittext上。并且有两个fragments
1。NewRequest
2。ModifyRequest
当我打开1个片段editImageButton
时将是不可见的,并且在2个片段中它将是可见的。但我不明白如何做到这一点。请建议我。
适配器类
public class TravelRequestDetailAdapter extends BaseAdapter {
private final LayoutInflater layoutInflater;
private List<TravelRequestAddDetails> mDataset;
private RequestDetailsFragment mContext;
private RequestDetailModification modification;
static class ViewHolder {
TextView TrDate, TrFrom, TrTo, TrAmount, TrDesc;
ImageButton RemoveItem, editItem;
}
@Override
public int getCount() {
return mDataset.size();
}
@Override
public TravelRequestAddDetails getItem(int position) {
return mDataset.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public void removeItem(int position) {
try {
mDataset.remove(position);
notifyDataSetChanged();
mContext.updateTotalAmount();
modification.updateTotalAmount();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.travel_request_adddetails, parent, false);
viewHolder = new ViewHolder();
viewHolder.TrDate = (TextView) convertView.findViewById(R.id.TDate);
viewHolder.TrFrom = (TextView) convertView.findViewById(R.id.TFrom);
viewHolder.TrTo = (TextView) convertView.findViewById(R.id.TTo);
viewHolder.TrAmount = (TextView) convertView.findViewById(R.id.TAmount);
viewHolder.TrDesc = (TextView) convertView.findViewById(R.id.TDesc);
viewHolder.RemoveItem = (ImageButton) convertView.findViewById(R.id.btn_delete);
viewHolder.editItem = (ImageButton) convertView.findViewById(R.id.btn_edit);
convertView.setTag(viewHolder);
}
viewHolder = (ViewHolder) convertView.getTag();
viewHolder.TrDate.setText(getItem(position).getTRAVELDATE());
viewHolder.TrFrom.setText(getItem(position).getTRAVELFROM());
viewHolder.TrTo.setText(getItem(position).getTRAVELTO());
viewHolder.TrAmount.setText(getItem(position).getAMOUNT());
viewHolder.TrDesc.setText(getItem(position).getDESCRIPTION());
viewHolder.RemoveItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeItem(position);
}
});
// viewHolder.editItem.setVisibility(View.GONE);
viewHolder.editItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
modification.editRequest();
}
});
return convertView;
}
public TravelRequestAddDetails getIteam(int position) {
return mDataset.get(position);
}
public TravelRequestDetailAdapter(List<TravelRequestAddDetails> myDataset, RequestDetailsFragment mContext) {
mDataset = myDataset;
this.mContext = mContext;
layoutInflater = (LayoutInflater) mContext.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public TravelRequestDetailAdapter(List<TravelRequestAddDetails> myDataset, RequestDetailModification mContext) {
mDataset = myDataset;
this.modification = mContext;
layoutInflater = (LayoutInflater) mContext.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}}
Pojo课程
public class TravelRequestAddDetails {
@SerializedName("REIMBURSEMENT_DTL_ID")
@Expose
private Integer rEIMBURSEMENTDTLID;
@SerializedName("REIMBURSEMENT_HDR_ID")
@Expose
private Integer rEIMBURSEMENTHDRID;
@SerializedName("TRAVEL_DATE")
@Expose
private String tRAVELDATE;
@SerializedName("TRAVEL_FROM")
@Expose
private String tRAVELFROM;
@SerializedName("TRAVEL_TO")
@Expose
private String tRAVELTO;
@SerializedName("AMOUNT")
@Expose
private String aMOUNT;
@SerializedName("DESCRIPTION")
@Expose
private String dESCRIPTION;
public TravelRequestAddDetails() {
}
public TravelRequestAddDetails(String tRAVELDATE, String tRAVELFROM, String tRAVELTO, String aMOUNT, String dESCRIPTION) {
this.tRAVELDATE = tRAVELDATE;
this.tRAVELFROM = tRAVELFROM;
this.tRAVELTO = tRAVELTO;
this.aMOUNT = aMOUNT;
this.dESCRIPTION = dESCRIPTION;
}
public Integer getREIMBURSEMENTDTLID() {
return rEIMBURSEMENTDTLID;
}
public void setREIMBURSEMENTDTLID(Integer rEIMBURSEMENTDTLID) {
this.rEIMBURSEMENTDTLID = rEIMBURSEMENTDTLID;
}
public Integer getREIMBURSEMENTHDRID() {
return rEIMBURSEMENTHDRID;
}
public void setREIMBURSEMENTHDRID(Integer rEIMBURSEMENTHDRID) {
this.rEIMBURSEMENTHDRID = rEIMBURSEMENTHDRID;
}
public String getTRAVELDATE() {
return tRAVELDATE;
}
public String setTRAVELDATE(String tRAVELDATE) {
this.tRAVELDATE = tRAVELDATE;
return tRAVELDATE;
}
public String getTRAVELFROM() {
return tRAVELFROM;
}
public String setTRAVELFROM(String tRAVELFROM) {
this.tRAVELFROM = tRAVELFROM;
return tRAVELFROM;
}
public String getTRAVELTO() {
return tRAVELTO;
}
public String setTRAVELTO(String tRAVELTO) {
this.tRAVELTO = tRAVELTO;
return tRAVELTO;
}
public String getAMOUNT() {
return aMOUNT;
}
public String setAMOUNT(String aMOUNT) {
this.aMOUNT = aMOUNT;
return aMOUNT;
}
public String getDESCRIPTION() {
return dESCRIPTION;
}
public String setDESCRIPTION(String dESCRIPTION) {
this.dESCRIPTION = dESCRIPTION;
return dESCRIPTION;
}
ModificationFragment Class
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.travel_request, container, false);
approverList=new ArrayList<>();
travelRequestAddDetailses = new ArrayList<>();
mAdapter = new TravelRequestDetailAdapter(travelRequestAddDetailses, this);
requestDetailsList = (ListView) rootView.findViewById(R.id.TravelRequestAdd);
requestDetailsList.setAdapter(mAdapter);
LayoutInflater inflaterHeader = getActivity().getLayoutInflater();
ViewGroup header = (ViewGroup) inflaterHeader.inflate(
R.layout.lc_modification, requestDetailsList, false);
requestDetailsList.addHeaderView(header);
LayoutInflater inflaterFooter = getActivity().getLayoutInflater();
ViewGroup footer = (ViewGroup) inflaterFooter.inflate(
R.layout.travel_details_footer, requestDetailsList, false);
requestDetailsList.addFooterView(footer);
raisedBy = (TextView) rootView.findViewById(R.id.text_raised);
approver = (TextView) rootView.findViewById(R.id.text_approver);
recyclerView = (RecyclerView) rootView.findViewById(R.id.wq_approver_recycler_view);
recyclerView.setHasFixedSize(true);
list = new ArrayList<>();
circleProgressBar = (CircleProgressBar) rootView.findViewById(R.id.progressBar);
travelFrom = (EditText) rootView.findViewById(R.id.txt_travel_from);
travelTo = (EditText) rootView.findViewById(R.id.txt_travel_to);
travelAmount = (EditText) rootView.findViewById(R.id.txt_amount);
travelDesc = (EditText) rootView.findViewById(R.id.txt_desc);
remark = (EditText) rootView.findViewById(R.id.remark);
documentList = (ListView) rootView.findViewById(R.id.documentList);
textViewTotal = (TextView) rootView.findViewById(R.id.txt_totalAmount);
selectDate = (TextView) rootView.findViewById(R.id.raiseddate);
dateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
selectTravelDate = (EditText) rootView.findViewById(R.id.texttravelDate);
selectTravelDate.setInputType(InputType.TYPE_NULL);
selectTravelDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectTravellingDate();
}
});
imgSelectedfile = (ImageView) rootView.findViewById(R.id.IVPCUploadDoc);
imgSelectedfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openFileChooser();
}
});
btn_add = (Button) rootView.findViewById(R.id.addButton);
btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (validateData(v)) {
addRequestDetails();
updateTotalAmount();
}
}
});
setRequestDetails();
return rootView;
}
public void addRequestDetails() {
TravelRequestAddDetails obj = new TravelRequestAddDetails(selectTravelDate.getText().toString(),
travelFrom.getText().toString(),
travelTo.getText().toString(),
travelAmount.getText().toString(),
travelDesc.getText().toString());
travelRequestAddDetailses.add(obj);
mAdapter.notifyDataSetChanged();
selectTravelDate.setText("");
travelFrom.setText("");
travelTo.setText("");
travelAmount.setText("");
travelDesc.setText("");
}
public void updateTotalAmount() {
int total = 0;
if (travelRequestAddDetailses != null && !travelRequestAddDetailses.isEmpty()) {
for (TravelRequestAddDetails travelRequestAddDetails : travelRequestAddDetailses) {
total = Integer.parseInt(travelRequestAddDetails.getAMOUNT()) + total;
}
}
textViewTotal.setText(total + "");
}
public void editRequest(){
for(int i=0;i<travelRequestAddDetailses.size();i++) {
// selectTravelDate.setText();
}
}}
答案 0 :(得分:0)
最好将您的储蓄存储在某些本地数据库或共享首选项中。然后随时访问它们。