마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

checkbox 체크한 것을 바로바로 TextView로 띄우기

0 추천
/***********************관심지역목록*************************/
 private static final String LOG_TAG = "Expandable";

 static final String si[] = { "서울시", "경기도", "부산시", "제주도" };

 static final String gu[][] = {
   // Shades of 서울
   { "서울시 >", "종로구", "서울시 >", "동대문구", "서울시 >",
     "용산구" },
   // Shades of 경기
   { "경기도 >", "용인시", "경기도 >", "수원시",
     "경기도 >", "의정부시" },
   // Shades of 부산
   { "부산시 > ", "영도구" },
   // Shades of 제주
   { "제주도 > ", "제주시"} };

 

 

  /**************************Expandable***************************/
  SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
    this, createGroupList(), // groupData describes the first-level
           // entries
    R.layout.group_row, // Layout for the first-level entries
    new String[] { "siName" }, // Key in the groupData maps to
            // display
    new int[] { R.id.childname }, // Data under "colorName" key goes
            // into this TextView
    createChildList(), // childData describes second-level entries
    R.layout.child_row, // Layout for second-level entries
    new String[] { "siName", "guName" }, // Keys in childData maps
              // to display
    new int[] { R.id.childname, R.id.guName } // Data under the keys
              // above go into these
              // TextViews
  );
  setListAdapter(expListAdapter);
  
 }

 

 

public void onContentChanged() {
  super.onContentChanged();
  Log.d(LOG_TAG, "onContentChanged");
 }

 public boolean onChildClick(ExpandableListView parent, View v,
   int groupPosition, int childPosition, long id) {
  Log.d(LOG_TAG, "onChildClick: " + childPosition);
  CheckBox cb = (CheckBox) v.findViewById(R.id.check1);
  
  if (cb != null)
   cb.toggle();
  return false;
 }

 public void onGroupExpand(int groupPosition) {
  Log.d(LOG_TAG, "onGroupExpand: " + groupPosition);
 }

 private List createGroupList() {
  ArrayList result = new ArrayList();
  for (int i = 0; i < si.length; ++i) {
   HashMap m = new HashMap();
   m.put("siName", si[i]);
   result.add(m);
  }
  return (List) result;
 }

 private List createChildList() {
  ArrayList result = new ArrayList();
  for (int i = 0; i < gu.length; ++i) {
   // Second-level lists
   ArrayList secList = new ArrayList();
   for (int n = 0; n < gu[i].length; n += 2) {
    HashMap child = new HashMap();
    child.put("siName", gu[i][n]);
    child.put("guName", gu[i][n + 1]);
    secList.add(child);
   }
   result.add(secList);
  }
  return result;
 }

 

-----------------------------------------------------------

Expandablelistview에서

childgroup의 체크박스에서 체크시

체크한 것을 바로바로 TextView로 띄워주려하는데

어떻게 띄울수 있을까요 ㅠㅠ

예를들어 서울시> 종로구가 체크되면

TextView로 서울시> 종로구가 띄워져야 합니다.

도와주세요 ㅠㅠ
lemooon (140 포인트) 님이 2014년 2월 11일 질문

1개의 답변

0 추천

checkbox객체에 setOnCheckedChangeListener를 등록하시구요.

 

그안에서 체크가 되었을 때 텍스트뷰에 표시하는 코드를 삽입하시면 됩니다.

 

각각의 checkbox의 구별은 checkbox객체의 setTag에 고유 텍스트를 저장하면 될 것같네요.

방귀과장 (18,940 포인트) 님이 2014년 2월 12일 답변
...