Сначала я получаю значения массива с сервера и показываю их в виде списка. После отображения в виде списка, они являются редактируемыми текстами в списке, откуда я могу изменить текст, который я показал в виде списка. Нет, я хочу снова отправить обновленные значения представления списка на сервер, который создает для меня проблему.
public class AdapterLeaveDateCalenderItem extends BaseAdapter {
private Context context;
private List<LeaveStaEndDTO> leaveStaEndDTOS33;
public AdapterLeaveDateCalenderItem(Context context, List<LeaveStaEndDTO> leaveStaEndDTOS) {
this.context = context;
this.leaveStaEndDTOS33 = leaveStaEndDTOS;
}
@Override
public int getCount() {
return leaveStaEndDTOS33.size();
}
@Override
public Object getItem(int position) {
return leaveStaEndDTOS33.get(position);
}
@Override
public long getItemId(int position) {
return leaveStaEndDTOS33.get(position).getMonth();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view55= LayoutInflater.from(parent.getContext()).inflate(R.layout.leave_fragment_calender_item,parent,false);
LeaveStaEndDTO leaveStaEndDTO33=leaveStaEndDTOS33.get(position);
((TextView)view55.findViewById(R.id.dateGetLeave)).setText(String.valueOf(leaveStaEndDTO33.getDate()));
((EditText)view55.findViewById(R.id.morningGetLeave)).setText(String.valueOf(leaveStaEndDTO33.getMorningValue()));
((EditText)view55.findViewById(R.id.afternoonGetLeave)).setText(String.valueOf(leaveStaEndDTO33.getAfternoonValue()));
return view55;
}
}
Это класс модели
public class LeaveStaEndDTO {
int id;
int morningValue;
int afternoonValue;
Boolean weekend;
int holyday;
int year;
int month;
int day;
String dayCode;
String date;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getMorningValue() {
return morningValue;
}
public void setMorningValue(int morningValue) {
this.morningValue = morningValue;
}
public int getAfternoonValue() {
return afternoonValue;
}
public void setAfternoonValue(int afternoonValue) {
this.afternoonValue = afternoonValue;
}
public Boolean getWeekend() {
return weekend;
}
public void setWeekend(Boolean weekend) {
this.weekend = weekend;
}
public int getHolyday() {
return holyday;
}
public void setHolyday(int holyday) {
this.holyday = holyday;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public String getDayCode() {
return dayCode;
}
public void setDayCode(String dayCode) {
this.dayCode = dayCode;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
Теперь это основной класс
public class LeavesFragment extends Fragment {
TextView l_startDate,l_endDate;
ListView calenderLeavesTotal;
EditText textArea_information;
public static String encoded33="";
public List<LeaveStaEndDTO> leaveStaEndDTOList;
ImageView picLoaderLeave,submitLeaveNew;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View viewlv=inflater.inflate(R.layout.fragment_leaves, container, false);
calenderLeavesTotal = (ListView)viewlv.findViewById(R.id.listViewLeavesCalender);
leaveStaEndDTOList = new ArrayList<>();
submitLeaveNew = (ImageView)viewlv.findViewById(R.id.submitLeaveNew);
textArea_information = (EditText)viewlv.findViewById(R.id.textArea_information);
picLoaderLeave = (ImageView)viewlv.findViewById(R.id.img_leave_crea_upload);
final Spinner spinner = (Spinner)viewlv.findViewById(R.id.spinnerYear);
final Spinner spinnerLeave = (Spinner)viewlv.findViewById(R.id.spinnerLeaveType);
l_startDate=(TextView) viewlv.findViewById(R.id.leave_start);
l_endDate=(TextView) viewlv.findViewById(R.id.leave_end);
calenderLeavesTotal.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String clickableId=String.valueOf(leaveStaEndDTOList.get(position).getId());
String clickableDate=String.valueOf(leaveStaEndDTOList.get(position).getDate());
String clickableMorning=String.valueOf(leaveStaEndDTOList.get(position).getMorningValue());
Toast.makeText(getContext(), clickableId+"\n"+clickableDate+"\n"+clickableMorning, Toast.LENGTH_SHORT).show();
}
});
spinner.setOnItemSelectedListener(this);
List<String> categories = new ArrayList<String>();
categories.add("2020");
categories.add("2021");
categories.add("2022");
categories.add("2023");
categories.add("2024");
categories.add("2025");
categories.add("2026");
categories.add("2027");
categories.add("2028");
categories.add("2029");
categories.add("2030");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item, categories);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String tu= String.valueOf(spinner.getSelectedItem());
utils.creLeaveYear = tu;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
ArrayAdapter<SelectDTO> leavesTypes = new ArrayAdapter<SelectDTO>(getContext(), android.R.layout.simple_spinner_item, utils.leavesTypeList);
leavesTypes.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerLeave.setAdapter(leavesTypes);
spinnerLeave.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
SelectDTO clickedDTo2 =(SelectDTO) parent.getSelectedItem();
displayLeavesTypes(clickedDTo2);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
l_startDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
l_startDate.setText(year+"-"+(monthOfYear + 1)+ "-"+ dayOfMonth);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
});
l_endDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (l_startDate.getText().toString().trim().isEmpty()){
Toast.makeText(getContext(), "Please select start date first", Toast.LENGTH_SHORT).show();
}else {
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
l_endDate.setText(year + "-"+(monthOfYear + 1) +"-"+ dayOfMonth);
getStaEndDateResponse();
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
}
});
picLoaderLeave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(getContext());
dialog.setContentView(R.layout.custom_image_dialogue);
TextView captureImage=dialog.findViewById(R.id.captureImage);
TextView selectGallery=dialog.findViewById(R.id.selectGallery);
TextView canDialog=dialog.findViewById(R.id.canBtn);
captureImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
}
});
selectGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 22);
}
});
canDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
submitLeaveNew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return viewlv;
}
private void getStaEndDateResponse() {
String endDate=l_endDate.getText().toString().trim();
String staDate=l_startDate.getText().toString().trim();
utils.creLeaveStartDate = staDate;
utils.creLeaveEndDate = endDate;
final ProgressDialog progress = new ProgressDialog(getContext());
progress.setTitle("Date Response");
progress.setMessage("Loading...");
progress.setCancelable(false); // disable dismiss by tapping outside of the dialog
progress.show();
SharedPreferences sharedPreferencesSet=getContext().getSharedPreferences(utils.SHARED_PREF_SET,MODE_PRIVATE);
user_token=sharedPreferencesSet.getString(utils.TEXT_SET,"");
utils.bear="Bearer ";
final RequestQueue requestQueue=Volley.newRequestQueue(getContext());
StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray jsonArray=new JSONArray(response);
for (int i=0 ; i < jsonArray.length() ; i++){
try {
JSONObject jsonObject=jsonArray.getJSONObject(i);
LeaveStaEndDTO leaveStaEndDTO=new LeaveStaEndDTO();
leaveStaEndDTO.setMorningValue(jsonObject.getInt("morningValue"));
leaveStaEndDTO.setAfternoonValue(jsonObject.getInt("afternoonValue"));
leaveStaEndDTO.setWeekend(jsonObject.getBoolean("weekend"));
leaveStaEndDTO.setYear(jsonObject.getInt("year"));
leaveStaEndDTO.setMonth(jsonObject.getInt("month"));
leaveStaEndDTO.setDay(jsonObject.getInt("day"));
leaveStaEndDTO.setDayCode(jsonObject.getString("dayCode"));
leaveStaEndDTO.setDate(jsonObject.getString("date"));
leaveStaEndDTOList.add(leaveStaEndDTO);
calenderLeavesTotal.setAdapter(new AdapterLeaveDateCalenderItem(getContext(),leaveStaEndDTOList));
progress.dismiss();
Toast.makeText(getContext(), response, Toast.LENGTH_SHORT).show();
}catch (Exception e){
progress.dismiss();
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
catch (JSONException e) {
progress.dismiss();
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progress.dismiss();
Toast.makeText(getContext(), error.toString(), Toast.LENGTH_SHORT).show();
}
}){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Accept","application/json");
headers.put("Authorization",utils.bear+utils.user_token);
return headers;
}
};
requestQueue.add(stringRequest);
}
private void displayLeavesTypes(SelectDTO clickedDTo2) {
int leaveType_id=clickedDTo2.getExpenseSelectDTOId();
String leaveType_code=clickedDTo2.getExpenseSelectDTOCode();
String leaveType_description=clickedDTo2.getExpenseSelectDTODescription();
utils.creLeaveTypeId = String.valueOf(leaveType_id);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 0)
{
if(data != null)
{
try {
Bitmap photo = (Bitmap) data.getExtras().get("data");
photo = Bitmap.createScaledBitmap(photo, 200, 200, true);
picLoaderLeave.setImageBitmap(photo);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
encoded33 = Base64.encodeToString(byteArray, Base64.DEFAULT);
utils.creLeaveFile = encoded33;
}
catch (Exception e){
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
else{
}
}
if (requestCode == 22){
try {
final Uri imageUri = data.getData();
final InputStream imageStream = getContext().getContentResolver().openInputStream(imageUri);
Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
selectedImage = Bitmap.createScaledBitmap(selectedImage, 200, 200, false);
picLoaderLeave.setImageBitmap(selectedImage);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
selectedImage.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
encoded33 = Base64.encodeToString(byteArray, Base64.DEFAULT);
utils.creLeaveFile = encoded33;
} catch (FileNotFoundException e) {
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
}
}