2017-03-01 72 views
0

我得到的兒童物品點擊的ID不正確。爲兒童物品點擊獲取不正確的ID點擊

片段類

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View itemView = inflater.inflate(R.layout.fragment_checklist_groups_description, container, false); 

     fragmentManager = getActivity().getSupportFragmentManager(); 
     mLinearListView = (LinearLayout) itemView.findViewById(R.id.linear_ListView); 

     //========================================================================= 

     for (int i = 0; i < 2; i++) { 
      V_ChecklistParentItemModel v_checklistParentItemModel = new V_ChecklistParentItemModel(); 
      v_checklistParentItemModel.setParentGroupID("" + (i + 1)); 
      v_checklistParentItemModel.setParentGroupName("Group Name " + i); 

      if (i == 0) { 
       v_checklistParentItemModel.setHasSubGroup(false); 

       ArrayList<V_ChecklistChildItemModel> tempV_checklistChildItemModelArrayList = new ArrayList<>(); 
       for (int j = 0; j < 3; j++) { 
        V_ChecklistChildItemModel v_checklistChildItemModel = new V_ChecklistChildItemModel(); 
        v_checklistChildItemModel.setChildItemQuestionID("" + (j + 1)); 
        v_checklistChildItemModel.setChildItemQuestionName("Description of Question " + (j + 1)); 
        v_checklistChildItemModel.setChildQuestionID("" + index); 
        index++; 

        tempV_checklistChildItemModelArrayList.add(v_checklistChildItemModel); 
       } 

       v_checklistParentItemModel.setV_checklistChildItemModelArrayList(tempV_checklistChildItemModelArrayList); 
      } else { 
       v_checklistParentItemModel.setHasSubGroup(true); 

       ArrayList<V_ChecklistSubGroupModel> tempV_checklistSubGroupModelArrayList = new ArrayList<>(); 
       for (int j = 0; j < 2; j++) { 
        V_ChecklistSubGroupModel v_checklistSubGroupModel = new V_ChecklistSubGroupModel(); 
        v_checklistSubGroupModel.setSubGroupID("" + (j + 1)); 

        if (j == 0) { 
         v_checklistSubGroupModel.setSubGroupName("Sub Group Name 2a"); 

         ArrayList<V_ChecklistChildItemModel> tempV_checklistChildItemModelArrayList = new ArrayList<>(); 
         for (int k = 0; k < 2; k++) { 
          V_ChecklistChildItemModel v_checklistChildItemModel = new V_ChecklistChildItemModel(); 
          v_checklistChildItemModel.setChildItemQuestionID("" + (k + 1)); 
          v_checklistChildItemModel.setChildItemQuestionName("Description of Question " + (k + 1)); 
          v_checklistChildItemModel.setChildQuestionID("" + index); 
          index++; 

          tempV_checklistChildItemModelArrayList.add(v_checklistChildItemModel); 
         } 

         v_checklistSubGroupModel.setV_checklistChildItemModelArrayList(tempV_checklistChildItemModelArrayList); 
        } else { 
         v_checklistSubGroupModel.setSubGroupName("Sub Group Name 2b"); 

         ArrayList<V_ChecklistChildItemModel> tempV_checklistChildItemModelArrayList = new ArrayList<>(); 
         for (int k = 0; k < 3; k++) { 
          V_ChecklistChildItemModel v_checklistChildItemModel = new V_ChecklistChildItemModel(); 
          v_checklistChildItemModel.setChildItemQuestionID("" + (k + 1)); 
          v_checklistChildItemModel.setChildItemQuestionName("Description of Question " + (k + 1)); 
          v_checklistChildItemModel.setChildQuestionID("" + index); 
          index++; 

          tempV_checklistChildItemModelArrayList.add(v_checklistChildItemModel); 
         } 

         v_checklistSubGroupModel.setV_checklistChildItemModelArrayList(tempV_checklistChildItemModelArrayList); 
        } 
        tempV_checklistSubGroupModelArrayList.add(v_checklistSubGroupModel); 
       } 
       v_checklistParentItemModel.setV_checklistSubGroupModelArrayList(tempV_checklistSubGroupModelArrayList); 
      } 
      v_checklistParentItemModelArrayList.add(v_checklistParentItemModel); 
     } 


     //========================================================================= 


     //Adds data into first row 
     for (int i = 0; i < v_checklistParentItemModelArrayList.size(); i++) { 
      Log.v("I : ", " " + i); 
      LayoutInflater listInflater = null; 
      listInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View mLinearView = listInflater.inflate(R.layout.custom_cardview_checklist_groups_description_main_parent_item, null); 

      final TextView mProductName = (TextView) mLinearView.findViewById(R.id.textViewName); 
      final RelativeLayout mImageArrowFirst = (RelativeLayout) mLinearView.findViewById(R.id.rlFirstArrow); 
      final LinearLayout mLinearScrollSecond = (LinearLayout) mLinearView.findViewById(R.id.linear_scroll); 

      //checkes if menu is already opened or not 
      if (isFirstViewClick == false) { 
       mLinearScrollSecond.setVisibility(View.GONE); 
       mImageArrowFirst.setBackgroundResource(R.drawable.next_disable_icon); 
      } else { 
       mLinearScrollSecond.setVisibility(View.VISIBLE); 
       mImageArrowFirst.setBackgroundResource(R.drawable.arw_down); 
      } 
      //Handles onclick effect on list item 
      mImageArrowFirst.setOnTouchListener(new View.OnTouchListener() { 
       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
        if (isFirstViewClick == false) { 
         isFirstViewClick = true; 
         mImageArrowFirst.setBackgroundResource(R.drawable.arw_down); 
         mLinearScrollSecond.setVisibility(View.VISIBLE); 
        } else { 
         isFirstViewClick = false; 
         mImageArrowFirst.setBackgroundResource(R.drawable.next_disable_icon); 
         mLinearScrollSecond.setVisibility(View.GONE); 
        } 
        return false; 
       } 
      }); 

      final String name = v_checklistParentItemModelArrayList.get(i).getParentGroupName(); 
      mProductName.setText(name); 

      if (v_checklistParentItemModelArrayList.get(i).isHasSubGroup()) { 
       //Adds data into second row 
       for (int j = 0; j < v_checklistParentItemModelArrayList.get(i).getV_checklistSubGroupModelArrayList().size(); j++) { 
        Log.v("J : ", " " + j); 
        LayoutInflater inflater2 = null; 
        inflater2 = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        View mLinearView2 = inflater2.inflate(R.layout.custom_cardview_checklist_groups_description_child_parent_item, null); 

        TextView mSubItemName = (TextView) mLinearView2.findViewById(R.id.textViewTitle); 
        final RelativeLayout mLinearSecondArrow = (RelativeLayout) mLinearView2.findViewById(R.id.linearSecond); 
        final RelativeLayout mImageArrowSecond = (RelativeLayout) mLinearView2.findViewById(R.id.rlSecondArrow); 
        final LinearLayout mLinearScrollThird = (LinearLayout) mLinearView2.findViewById(R.id.linear_scroll_third); 
        final LinearLayout linearLayoutMain = (LinearLayout) mLinearView2.findViewById(R.id.llMain); 

        if (i == 0) { 
         mLinearSecondArrow.setBackgroundColor(getResources().getColor(R.color.main_parent)); 
         mImageArrowSecond.setVisibility(View.GONE); 
         linearLayoutMain.setPadding(20, 0, 0, 0); 
        } else { 
         mLinearSecondArrow.setBackgroundColor(getResources().getColor(R.color.child_parent)); 
         mImageArrowSecond.setVisibility(View.VISIBLE); 

         if (i == 1) { 
          linearLayoutMain.setPadding(20, 8, 0, 0); 
         } else { 
          linearLayoutMain.setPadding(15, 8, 0, 0); 
         } 
        } 

        //checkes if menu is already opened or not 
        if (isSecondViewClick == false) { 
         mLinearScrollThird.setVisibility(View.GONE); 
         mImageArrowSecond.setBackgroundResource(R.drawable.next_disable_icon); 
        } else { 
         mLinearScrollThird.setVisibility(View.VISIBLE); 
         mImageArrowSecond.setBackgroundResource(R.drawable.arw_down); 
        } 

        //Handles onclick effect on list item 
        if (i == 0) { 
         final int finalI1 = i; 
         final int finalJ1 = j; 
         mLinearSecondArrow.setOnTouchListener(new View.OnTouchListener() { 
          @Override 
          public boolean onTouch(View v, MotionEvent event) { 
           Bundle bundle = new Bundle(); 
           bundle.putString("groupName", v_checklistParentItemModelArrayList.get(finalI1).getParentGroupName()); 
           bundle.putInt("itemCount", 3); 
           bundle.putSerializable("alldata", checklist_groupNamePojoArrayList); 
           pageNumber = 0; 
           bundle.putInt("pageNumber", pageNumber); 

           ChecklistGroupsQuestionsMainDialogFragment checklistGroupsQuestionsMainDialogFragment = new ChecklistGroupsQuestionsMainDialogFragment(); 
           checklistGroupsQuestionsMainDialogFragment.setArguments(bundle); 
           checklistGroupsQuestionsMainDialogFragment.setTargetFragment(current, 101); 
           checklistGroupsQuestionsMainDialogFragment.show(fragmentManager, getResources().getString(R.string.sd_project_list_screen_name)); 

           return false; 
          } 
         }); 
        } else { 
         mImageArrowSecond.setOnTouchListener(new View.OnTouchListener() { 
          @Override 
          public boolean onTouch(View v, MotionEvent event) { 
           if (isSecondViewClick == false) { 
            isSecondViewClick = true; 
            mImageArrowSecond.setBackgroundResource(R.drawable.arw_down); 
            mLinearScrollThird.setVisibility(View.VISIBLE); 

           } else { 
            isSecondViewClick = false; 
            mImageArrowSecond.setBackgroundResource(R.drawable.next_disable_icon); 
            mLinearScrollThird.setVisibility(View.GONE); 
           } 
           return false; 
          } 
         }); 
        } 

        final String catName = v_checklistParentItemModelArrayList.get(i).getV_checklistSubGroupModelArrayList().get(j).getSubGroupName(); 
        mSubItemName.setText(catName); 
        //Adds items in subcategories 
        for (int k = 0; k < v_checklistParentItemModelArrayList.get(i).getV_checklistSubGroupModelArrayList().get(j).getV_checklistChildItemModelArrayList().size(); k++) { 
         Log.v("K : ", " " + k); 
         LayoutInflater inflater3 = null; 
         inflater3 = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
         View mLinearView3 = inflater3.inflate(R.layout.custom_cardview_checklist_groups_description_child_item, null); 
         TextView mItemName = (TextView) mLinearView3.findViewById(R.id.textViewItemName); 
         final String itemName = v_checklistParentItemModelArrayList.get(i).getV_checklistSubGroupModelArrayList().get(j).getV_checklistChildItemModelArrayList().get(k).getChildItemQuestionName(); 
         mItemName.setText(itemName); 

         mLinearScrollThird.addView(mLinearView3); 

         final int finalI = i; 
         final int finalJ = j; 
         final int finalK = k; 
         mLinearScrollThird.setOnTouchListener(new View.OnTouchListener() { 
          @Override 
          public boolean onTouch(View v, MotionEvent event) { 
           Bundle bundle = new Bundle(); 
           bundle.putString("groupName", v_checklistParentItemModelArrayList.get(finalI).getParentGroupName()); 
           bundle.putInt("itemCount", v_checklistParentItemModelArrayList.get(finalI).getV_checklistSubGroupModelArrayList().get(finalJ).getV_checklistChildItemModelArrayList().size()); 
//       bundle.putSerializable("questionData", group2bQuestionList); 
           bundle.putSerializable("alldata", checklist_groupNamePojoArrayList); 
           pageNumber = finalI + finalJ + finalK + 1; 
           bundle.putInt("pageNumber", pageNumber); 

           Log.v("====ugugugu==", "===ijhbjhbjh==="); 
           Toast.makeText(getActivity(), "Page No. " + v_checklistParentItemModelArrayList.get(finalI).getV_checklistSubGroupModelArrayList().get(finalJ).getV_checklistChildItemModelArrayList().get(finalK).getChildQuestionID(), Toast.LENGTH_LONG).show(); 

           ChecklistGroupsQuestionsMainDialogFragment checklistGroupsQuestionsMainDialogFragment = new ChecklistGroupsQuestionsMainDialogFragment(); 
           checklistGroupsQuestionsMainDialogFragment.setArguments(bundle); 
           checklistGroupsQuestionsMainDialogFragment.setTargetFragment(current, 101); 
           checklistGroupsQuestionsMainDialogFragment.show(fragmentManager, getResources().getString(R.string.check_list_groups_question_screen_name)); 

           return false; 
          } 
         }); 
        } 
        mLinearScrollSecond.addView(mLinearView2); 
       } 
       mLinearListView.addView(mLinearView); 
      } else { 
       //Adds items in subcategories 
       for (int k = 0; k < v_checklistParentItemModelArrayList.get(i).getV_checklistChildItemModelArrayList().size(); k++) { 
        Log.v("K : ", " " + k); 
        LayoutInflater inflater3 = null; 
        inflater3 = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        View mLinearView3 = inflater3.inflate(R.layout.custom_cardview_checklist_groups_description_child_item, null); 
        final LinearLayout mLinearScrollThird = (LinearLayout) mLinearView3.findViewById(R.id.linear_scroll_third); 
        TextView mItemName = (TextView) mLinearView3.findViewById(R.id.textViewItemName); 
        final String itemName = v_checklistParentItemModelArrayList.get(i).getV_checklistChildItemModelArrayList().get(k).getChildItemQuestionName(); 
        mItemName.setText(itemName); 

        final int finalI = i; 
        final int finalK = k; 
        mLinearScrollThird.setOnTouchListener(new View.OnTouchListener() { 
         @Override 
         public boolean onTouch(View v, MotionEvent event) { 
          Bundle bundle = new Bundle(); 
          bundle.putString("groupName", v_checklistParentItemModelArrayList.get(finalI).getParentGroupName()); 
          bundle.putInt("itemCount", v_checklistParentItemModelArrayList.get(finalI).getV_checklistChildItemModelArrayList().size()); 
          bundle.putSerializable("alldata", checklist_groupNamePojoArrayList); 
          bundle.putInt("pageNumber", 1); 

          Toast.makeText(getActivity(), "Page No. " + v_checklistParentItemModelArrayList.get(finalI).getV_checklistChildItemModelArrayList().get(finalK).getChildQuestionID(), Toast.LENGTH_LONG).show(); 

          ChecklistGroupsQuestionsMainDialogFragment checklistGroupsQuestionsMainDialogFragment = new ChecklistGroupsQuestionsMainDialogFragment(); 
          checklistGroupsQuestionsMainDialogFragment.setArguments(bundle); 
          checklistGroupsQuestionsMainDialogFragment.setTargetFragment(current, 101); 
          checklistGroupsQuestionsMainDialogFragment.show(fragmentManager, getResources().getString(R.string.check_list_groups_question_screen_name)); 

          return false; 
         } 
        }); 

        mLinearScrollSecond.addView(mLinearView3); 
       } 
       mLinearListView.addView(mLinearView); 
      } 
     } 

     //============================================================================== 


     return itemView; 
    } 

我已經使用setChildQuestionID分配兒童問題ID()。對於組名稱0,每次點擊時我都會得到0,1,2。但是,對於組名稱1,對於子組名稱2a,對於子組名稱2a,我得到4爲子組名稱2a & 7。理想情況下,它應該返回我爲他們設定的任何東西。

回答

0

您的意思是說,您希望在組名1中獲得兒童點擊的0,1,2?據我所知,你將不得不重新設置索引的值爲0來獲得。至少,假設你已經在最外層的for循環之外的某個地方定義了index = 0(我看不到你的代碼在哪裏設置了index的值)。眼下在0組,您可以:

     for (int k = 0; k < 2; k++) { 
         V_ChecklistChildItemModel v_checklistChildItemModel = new V_ChecklistChildItemModel(); 
         v_checklistChildItemModel.setChildItemQuestionID("" + (k + 1)); 
         v_checklistChildItemModel.setChildItemQuestionName("Description of Question " + (k + 1)); 
         v_checklistChildItemModel.setChildQuestionID("" + index); 
         index++; 

如果指數爲0,開始時,指數值現在大於0,不設回0,所以當你到了下一個循環通過頂級for循環,索引的值已經大於0.如果要在組1的索引= 0處重新開始,則必須將索引的值設置回0.

換句話說,您正在返回您爲questionID設置的內容,但我認爲您正在設置一個您不想設置的數字。