ui_form.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * ui_form.h
  3. *
  4. * Created on: 2021年8月20日
  5. * Author: pengzc
  6. */
  7. #ifndef JNI_CORE_UI_FORM_H_
  8. #define JNI_CORE_UI_FORM_H_
  9. #include "field.h"
  10. #include "control/ZKListView.h"
  11. class UIForm : public ZKListView::IItemClickListener,
  12. public ZKListView::AbsListAdapter {
  13. public:
  14. virtual ~UIForm();
  15. void Add(Field& field) {
  16. fields.push_back((Field*)&field);
  17. }
  18. void BindView(ZKListView* list_view) {
  19. list_view->setItemClickListener(this);
  20. list_view->setListAdapter(this);
  21. list_view_ = list_view;
  22. }
  23. void BindIds(int icon_id, int title_id,
  24. int value_id, int arraw_id, int only_title_id,
  25. int switch_id) {
  26. ids[Field::ICON] = icon_id;
  27. ids[Field::TITLE] = title_id;
  28. ids[Field::VALUE] = value_id;
  29. ids[Field::ARRAW] = arraw_id;
  30. ids[Field::ONLY_TITLE] = only_title_id;
  31. ids[Field::SWITCH] = switch_id;
  32. }
  33. void BindId(int key, int id) {
  34. ids[key] = id;
  35. }
  36. void Clear() {
  37. for (auto& f : fields) {
  38. delete f;
  39. }
  40. fields.clear();
  41. ids.clear();
  42. }
  43. void Invalidate() {
  44. if (list_view_) {
  45. list_view_->refreshListView();
  46. }
  47. }
  48. protected:
  49. virtual int getListItemCount(const ZKListView *pListView) const;
  50. virtual void obtainListItemData(ZKListView *pListView,
  51. ZKListView::ZKListItem *pListItem, int index);
  52. virtual void onItemClick(ZKListView *pListView, int index, int itemID);
  53. private:
  54. friend class Field;
  55. std::vector<Field*> fields;
  56. std::map<int, int> ids;
  57. ZKListView* list_view_;
  58. };
  59. #endif /* JNI_CORE_UI_FORM_H_ */