2017-11-03 24 views
0

こんにちは私のテーブルレイアウトでは、私は動的に作成されたいくつかのテーブル行を持っています。各行には約5つのビュー、1つのオートコンプリート・テキスト・ビューと4つの編集テキストがあります。TableLayoutでのループとすべてのビューの値の取得

私はテーブルレイアウトの外にボタンがあります。ユーザーがクリックすると、テーブルをループして各ビューの値を取得できます。

答えて

0

わかりました私はいくつかの助けを借りて、それを解決しているように見える:

private void saveUserInput() { 
    mWeekdays = new JSONArray(); 
    mSchedules = new JSONArray(); 

    for(int c = 0; c < mWeekdaysView.getChildCount(); c++) 
    { 
     View child = mWeekdaysView.getChildAt(c); 
     if (child != null && child instanceof TableRow) 
     { 
      TableRow row = (TableRow) child; 

      for(int i = 0; i < row.getChildCount(); i++) { 
       View input = row.getChildAt(i); 

       if (input != null && input instanceof CheckBox) { 
        CheckBox checkBox = (CheckBox) input; 

        if (checkBox.isChecked()) { 
         mWeekdays.put(checkBox.getText().toString().toLowerCase()); 
        } 
       } 
      } 
     } 
    } 

    for(int j = 0; j < mWeekdays.length(); j++) { 


     for(int c = 0; c < mSchedulesView.getChildCount(); c++) 
     { 
      View child = mSchedulesView.getChildAt(c); 
      if (child != null && child instanceof TableRow) 
      { 
       TableRow row = (TableRow) child; 

       JSONObject schedule = new JSONObject(); 
       for(int i = 0; i < row.getChildCount(); i++) { 
        View input = row.getChildAt(i); 

        if (input != null && input instanceof EditText) { 
         try { 
          EditText editText = (EditText) input; 
          schedule.put(editText.getHint().toString().replace(" ", "_").toLowerCase(), editText.getText().toString()); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 
       } 

       try { 
        schedule.put("weekday", mWeekdays.getString(j)); 
       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 

       mSchedules.put(schedule); 
      } 
     } 

    } 

} 

AutoCompleteTextViewがのEditTextと解釈され、なぜ私の唯一の問題は今あります。

関連する問題