본문 바로가기
개발공부/Java & 안드로이드

[안드로이드] ChipGroup에서 text 얻는 방법

by 안스토리 2022. 7. 27.

// chipGroup에서 선택된 chip의 text 값 얻는 방법
List<Integer> a = chipGroup.getCheckedChipIds();
Log.i(TAG, "chipGroup.getCheckedChipIds() = " + chipGroup.getCheckedChipIds());
Log.i(TAG, "a.get(0) = " + a.get(0));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a.size(); i++){
    Chip r = (Chip) chipGroup.getChildAt(chipGroup.indexOfChild(chipGroup.findViewById(a.get(i))));
    String selectedText = r.getText().toString();
    sb.append(selectedText+"-");
    Log.i(TAG, "a.get("+i+") = " + a.get(i));
    Log.i(TAG, "selectedText = " + selectedText);
}

String result = sb.toString();
result = result.substring(0, result.length() -1);
Log.i(TAG, "result = " + result);