我必须这样做。
我可以显示数据,当按下一个按钮时,它会显示下一个11项//但我想从当前日期设置列表。 然后用户按下一个按钮,它将显示数组的下一个11项结束。 并且用户按下前一个按钮,它将显示当前按列表的11个项目结束的上一个日期。
当我要编辑或删除
时,也会自动更改edittext的值下面是我的代码
int NUM_ITEMS_JUMP= 0; int NUM_ITEMS_PAGE = 11; int licount = 0; private void loadList(int number) { moByDayArrayList = new ArrayList<>(); for (int i = -50; i < 0; i++) { moByDayArrayList.add(new ByDay(Common.getCalculatedDates(Common.getCurrentDate(), i), "3")); } //Previous 60 Days for (int i = 0; i < 60; i++) { //moByDayArrayList.add(new ByDay(Common.getCalculatedDate(i))); moByDayArrayList.add(new ByDay(Common.getCalculatedDates(Common.getCurrentDate(), i), "5")); } System.out.println("moByDayArrayList.size() " + moByDayArrayList.size()); ArrayList<ByDay> sort = new ArrayList<ByDay>(); for (int i = number; i < (number) + NUM_ITEMS_PAGE; i++) { if (i < moByDayArrayList.size()) { sort.add(moByDayArrayList.get(i)); System.out.println("sort.size() sort " + sort.size()); } else { System.out.println("No more"); if (licount == 1) { Common.makeAlert(getActivity(), "No more data available", true); } else { licount++; } break; } } NUM_ITEMS_JUMP+= 11; byDayListAdapter = new ByDayListAdapter(getActivity(), sort); moLvByDay.setAdapter(byDayListAdapter); //moLvByDay.setSelection(moByDayArrayList.indexOf(moByDayArrayList.get(40).getStartDate())); // Not Working }
onCreate
loadList(0);
下一步按钮单击
loadList(NUM_ITEMS_JUMP);
适配器
public class ByDayListAdapter extends ArrayAdapter<ByDay> { Context context; List<ByDay> maByDay; @Override public int getCount() { return maByDay.size(); } public ByDayListAdapter(Context context, int resource, int textViewResourceId) { super(context, resource, textViewResourceId); } public ByDayListAdapter(Context context, List<ByDay> faByDay) { super(context, 0, faByDay); this.context = context; this.maByDay = faByDay; } @Override public View getView(int position, View convertView, ViewGroup parent) { // Get the data item for this position ByDay loByDay = getItem(position); // Check if an existing view is being reused, otherwise inflate the view if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.listitem_byday, parent, false); } // Lookup view for data population EditText etName = (EditText) convertView.findViewById(R.id.etByDayTime); TextView tvHome = (TextView) convertView.findViewById(R.id.tvByDayDate); if (Common.getCurrentDate().equalsIgnoreCase(loByDay.getStartDate())) { System.out.println("from day -- lsStartDate.... " + loByDay.getStartDate() + "\nCommon.getCurrentDate()....... " + Common.getCurrentDate()); tvHome.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); tvHome.setTextColor(ActivityCompat.getColor(context, R.color.black_light)); } else { tvHome.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); tvHome.setTextColor(ActivityCompat.getColor(context, R.color.gray)); } tvHome.setText(loByDay.getStartDate()); etName.setText(loByDay.getHours()); etName.addTextChangedListener(new EditTextWatcher(loByDay)); // Return the completed view to render on screen return convertView; } public class EditTextWatcher implements TextWatcher { private ByDay byDay; public EditTextWatcher(ByDay byDay) { this.byDay = byDay; } @Override public void afterTextChanged(Editable s) { byDay.setHours(s.toString()); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } } }
屏幕截图
如何获得这种方法?还有其他方法吗?或者可以通过listview来做到这一点?请帮帮我。