2012-06-13 3 views
6

나는 이런 식으로하려고합니다. 확장 가능 목록은 특정 범주의 이름으로 구성되며 부모를 클릭하면 해당 범주의 모든 하위 목록이 표시됩니다. 이제 모든 카테고리에 하위 항목을 동적으로 추가하고 싶습니다. 어떻게하면됩니까? 목록에있는 모든 상위 항목과 함께 하위 항목을 추가하는 단추를 계속 누르고 있습니까?Android ExpandableList 뷰 버튼이있는 부모

다른 포럼을 둘러 보았을 때 모든 부모 내부에서 버튼 클릭 처리기를 설정하는 것이 쉽지 않음을 알게되었습니다. 그러나 그것이 유일한 방법이라면 누구든지 샘플 코드를 알려 주실 수 있습니까?

이 스레드를 발견했지만 코드에서 구현할 수 없습니다. Android Row becomes Unclickable with Button

+0

? 커서에서? 배열로? – Barak

+0

배열을 사용하고 있습니다. – Swayam

답변

6

버튼을 그룹보기에 추가하는 것이 그렇게 어렵지 않아야합니다.

나는 아래의 작업을해야한다고 믿는다. (테스트를 위해 어레이에 지원되는 ExpandableListView를 사용하는 프로젝트는 없다.)

그룹 행 레이아웃을 모르기 때문에 여기를 참조 용으로 만듭니다.

group_layout.xml 어댑터에서 getGroupView 방법 그리고

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/test" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 
    <TextView 
     android:id="@android:id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="35dp" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:gravity="center_vertical" 
     android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
    <Button 
     android:id="@+id/addbutton" 
     android:layout_width="wrap_content" 
     android:layout_height="35dp" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:text="Add" 
     android:textSize="12dp" /> 
</LinearLayout> 

: 어떻게 당신이 목록을 채우는 있습니다

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    if (convertView == null) { 
     View convertView = View.inflate(getApplicationContext(), R.layout.group_layout, null); 
     Button addButton = (Button)convertView.findViewById(R.id.addButton); 

     addButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       // your code to add to the child list 
      } 
     }); 
    }   
    TextView textView = (TextView)convertView.findViewById(R.id.text1); 
    textView.setText(getGroup(groupPosition).toString()); 
    return convertView; 
} 
관련 문제