2017-12-14 5 views
1

모두 안녕하세요, 어댑터에서 동적으로 childview의 라디오 버튼을 생성하는 애플리케이션에서 확장 가능한 목록보기가 있습니다. 확장형 목록보기에서 setOnChildClickListener에 대한 요구 사항이 있습니다. 하지만 불행히도 라디오 버튼 때문에 해고되지 않습니다. 동적으로 생성 된 라디오 버튼에서 setFocusable/setclickable을 false로 설정하려고했습니다. 내가 할 때 setOnChildClickListener가 해고 당한다. 하지만 개별 라디오 버튼을 선택할 수 없습니다. 아무도 도왔습니다. 아무도 이것으로 나를 도울 수 있습니까?setOnChildClickListener가 ExpandableListView에 대해 실행되지 않습니다.

이 내 어댑터 방법

@Override 
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    LayoutInflater infalInflater = (LayoutInflater) this.context 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    convertView = infalInflater.inflate(R.layout.expandable_child_radio_layout, null); 


    RadioGroup radioGroup = (RadioGroup) convertView.findViewById(R.id.radio_group1); 
    radioGroup.setFocusable(false); 
    final RadioButton[] rb = new RadioButton[listDataChild.get(this.listOptionsHeader.get(groupPosition)).size()]; 
    radioGroup.setOrientation(RadioGroup.VERTICAL); 
    for (int i = 0; i < listDataChild.get(this.listOptionsHeader.get(groupPosition)).size(); i++) { 
     rb[i] = new RadioButton(context); 
     rb[0].setChecked(true); 
     final String childText = (String) getChild(groupPosition, i); 
     rb[i].setText(childText); 
     rb[i].setId(i + 100); 
     rb[i].setTag("radio-child " + childText); 
     fontUtils.changeFontOfRadioButtontoOpenSansRegular(rb[i]); 
     rb[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.letter_small)); 
     radioGroup.addView(rb[i]); 
     rb[i].setFocusable(false); 
    } 
    return convertView; 
} 

입니다, 내 어댑터 클래스의 방법이 내 아이의 레이아웃 XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="left" 
    android:layoutDirection="ltr" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:paddingLeft="20dp"> 

     <RadioGroup 
      android:id="@+id/radio_group1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     </RadioGroup> 

    </LinearLayout> 

</LinearLayout> 

되는 참조하시기 바랍니다 이것은 내 주요 활동 클래스에서 사용한 온 클릭 방법 .

+0

난 당신이 childview 위해'mExpandableListView.setOnChildClickListener을 리스너를 적용하는 것을 잊었다 생각 클릭 된 버튼에 수동으로 선택을 추가 할 수); ' –

+0

만약 당신이 청취자와 함께 코드를 게시하지 않았다면, 문제는 버튼이 아니며, 또한 문서가 ExListView에 대한 높이 wrap_content를 사용하는 것을 제한하고 동시에 부모 레이아웃을 지정해야합니다. xml 레이아웃의 높이 – Rainmaker

+0

@HarshadPrajapati 내가 hav 사실 내 주요 활동 수업에서 리스너를 사용했습니다. – DRayen

답변

1

귀사에 return 문을 false가 아닌 true로 설정하고 어댑터를 설정 한 후에 설정해야합니다!

편집 : 당신이 rbuttons을 선택하지 못할하지만의 OnClick 해고됨에 따라

의이 (

RadioGroup radioGroup = (RadioGroup) convertView.findViewById(R.id.radio_group1); 
radioGroup.setFocusable(false); 
final RadioButton[] rb = new RadioButton[listDataChild.get(this.listOptionsHeader.get(groupPosition)).size()]; 
radioGroup.setOrientation(RadioGroup.VERTICAL); 
for (int i = 0; i < listDataChild.get(this.listOptionsHeader.get(groupPosition)).size(); i++) { 
    rb[i] = new RadioButton(context); 
    // rb[0].setChecked(true); 
    final String childText = (String) getChild(groupPosition, i); 
    rb[i].setText(childText); 
    rb[i].setId(i + 100); 
    rb[i].setTag("radio-child " + childText); 
    fontUtils.changeFontOfRadioButtontoOpenSansRegular(rb[i]); 
    rb[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.letter_small)); 
    radioGroup.addView(rb[i]); 
    rb[i].setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      radioGroup.check(rb[i].getId()); 
     //if you allow multiple checked btns then leave it like that or if you don't then you need to check if there are other buttons checked in radioGroup and then unckeck them also in this method 
     }); 
    rb[i].setFocusable(false); 
+0

사실로 변경했습니다. 그러나 나는 아직도 인쇄 진술을 얻지 못한다. – DRayen

+0

뷰가 focusable = false로 설정되어 있고 clickable = false로 설정되어 있습니다. 클릭 수를 잡을 수 없으므로 true로 변경하십시오. – Rainmaker

+0

false로 설정하면'setOnChildClickListener'가 실행되지만 개별 라디오 버튼을 선택할 수 없습니다. true로 변경하면 개별 라디오 버튼을 선택할 수 있지만'setOnChildClickListener'는 실행되지 않습니다. – DRayen

관련 문제