Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.14 KB | None | 0 0
  1. otherSchool.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  2. @Override
  3. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  4. if (position == 0) {
  5. if (allSchoolClassesName.size() > 0) {
  6. for (int j = 0; j < allSchoolClassesName.size(); j++) {
  7. final CheckBox addonChechbox = new CheckBox(context);
  8. addonChechbox.setText("");
  9. dialog_checkboox_options_dynamic_school_class.removeView(addonChechbox);
  10. addonChechbox.setText(allSchoolClassesName.get(j));
  11. addonChechbox.setId(j);
  12. addonChechbox.setTextColor(context.getResources().getColor(R.color.White));
  13. addonChechbox.setButtonDrawable(context.getResources().getDrawable(R.drawable.selector_checkbox));
  14. addonChechbox.setPadding(0, 0, 0, 0);
  15. addonChechbox.setTextColor(context.getResources().getColor(R.color.black));
  16. addonChechbox.setTypeface(tf);
  17.  
  18. for (int groupIds = 0; groupIds < groupsArray.size(); groupIds++) {
  19. if (allSchoolClassesId.get(j).equalsIgnoreCase(groupsArray.get(groupIds))) {
  20. addonChechbox.setChecked(true);
  21. addonChechbox.setButtonDrawable(context.getResources().getDrawable(R.drawable.selector_checkbox));
  22. selectedGroupId.add(allSchoolClassesId.get(addonChechbox.getId()));
  23. selectedGroupType.add("1");
  24. }
  25. }
  26. dialog_checkboox_options_dynamic_school_class.addView(addonChechbox);
  27. addonChechbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  28. @Override
  29. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  30.  
  31. if (isChecked) {
  32.  
  33. selectedGroupId.add(allSchoolClassesId.get(addonChechbox.getId()));
  34. selectedGroupType.add("1");
  35. } else {
  36. boolean findSelectedId = selectedGroupId.contains(allSchoolClassesId.get(addonChechbox.getId()));
  37. if (findSelectedId) {
  38. int indexSelectedId = selectedGroupId.indexOf(allSchoolClassesId.get(addonChechbox.getId()));
  39. selectedGroupId.remove(indexSelectedId);
  40. selectedGroupType.remove(indexSelectedId);
  41. }
  42. }
  43. }
  44. });
  45. }
  46. }
  47. } else if (position > 0) {
  48. if (schData.length() > 0) {
  49. int i = 1;
  50. int pos = position;
  51. for (int k = 0; schData.length() > 0; k++) {
  52. if (position == i) {
  53. JSONObject achArray = schData.optJSONObject(k);
  54. JSONArray grpList = achArray.optJSONArray("grpList");
  55. for (int j = 0; j < grpList.length(); j++) {
  56. final CheckBox addonChechbox = new CheckBox(context);
  57. addonChechbox.setText("");
  58. dialog_checkboox_options_dynamic_school_class.removeView(addonChechbox);
  59. JSONObject classObj = grpList.optJSONObject(j);
  60. String classes = classObj.optString("classes");
  61. JSONObject jsonObjectId = classObj.optJSONObject(Constants.CONSTANT_id);
  62. final String classGroupId = jsonObjectId.optString(Constants.CONSTANT_$id);
  63. addonChechbox.setText("");
  64. addonChechbox.setText(classes);
  65. addonChechbox.setId(j);
  66. addonChechbox.setTextColor(context.getResources().getColor(R.color.White));
  67. addonChechbox.setButtonDrawable(context.getResources().getDrawable(R.drawable.selector_checkbox));
  68. addonChechbox.setPadding(0, 0, 0, 0);
  69. addonChechbox.setTextColor(context.getResources().getColor(R.color.black));
  70. addonChechbox.setTypeface(tf);
  71.  
  72. for (int groupIds = 0; groupIds < groupsArray.size(); groupIds++) {
  73. if (classGroupId.equalsIgnoreCase(groupsArray.get(groupIds))) {
  74. addonChechbox.setChecked(true);
  75. addonChechbox.setButtonDrawable(context.getResources().getDrawable(R.drawable.selector_checkbox));
  76. selectedGroupId.add(classGroupId);
  77. selectedGroupType.add("1");
  78. }
  79. }
  80. dialog_checkboox_options_dynamic_school_class.removeView(addonChechbox);
  81. dialog_checkboox_options_dynamic_school_class.addView(addonChechbox);
  82. addonChechbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  83. @Override
  84. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  85.  
  86. if (isChecked) {
  87.  
  88. selectedGroupId.add(classGroupId);
  89. selectedGroupType.add("1");
  90. } else {
  91. boolean findSelectedId = selectedGroupId.contains(classGroupId);
  92. if (findSelectedId) {
  93. int indexSelectedId = selectedGroupId.indexOf(classGroupId);
  94. selectedGroupId.remove(indexSelectedId);
  95. selectedGroupType.remove(indexSelectedId);
  96. }
  97. }
  98. }
  99. });
  100. }
  101. break;
  102. }
  103. i++;
  104. }
  105. }
  106. }
  107. }
  108.  
  109. @Override
  110. public void onNothingSelected(AdapterView<?> parent) {
  111.  
  112. }
  113. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement