1

내 자신의 버전의 ArrayAdapter를 사용하여 사용자 지정 ListView를 만들었습니다. 내 문제는 모든 onItemClickListeners에 응답하지 않는다는 것입니다.사용자 지정 ListView (CheckBox 포함)가 클릭에 응답하지 않음

final ArrayAdapter<Agency> aa=new myCustomAdapter(); 
    lv.setAdapter(aa); 

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View myView, int pos, 
       long id) { 
      TextView clickedTV=(TextView)myView.findViewById(R.id.rowtext1); 
      Toast.makeText(getBaseContext(), clickedTV.getText().toString(), Toast.LENGTH_LONG).show(); 


     } 
    }); 

어댑터 구현 : : 다음 내 어댑터 팽창 각 행에 대해 사용자 지정 XML 레이아웃을 생성 한

private class myCustomAdapter extends ArrayAdapter<Agency> { 

    public myCustomAdapter() { 
     super(getBaseContext(), R.layout.layout_row, AgencyList); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View itemView=convertView; 
     if (itemView==null) 
      itemView=getLayoutInflater().inflate(R.layout.layout_row, parent, false); 
     TextView rowText=(TextView)itemView.findViewById(R.id.rowtext1); 
     Agency currentAgency=AgencyList.get(position); 
     rowText.setText(currentAgency.getAgency().toString()); 
     return itemView; 
    } 
} 

여기 내 코드 조각입니다. 사용자 정의 행 레이아웃은 텍스트 뷰와 체크 박스가 있습니다

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/rowtext1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="23dp" 
     android:layout_marginTop="21dp" 
     android:text="Row Item" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <CheckBox 
     android:id="@+id/rowcheckBox1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/rowtext1" 
     android:layout_alignBottom="@+id/rowtext1" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="26dp" 
     android:text="Select this" /> 

</RelativeLayout> 

이미 (체크 박스 같은) 클릭 할 수있는 위젯 거기에리스트 뷰에서 클릭 할 수있는 행이 없다? 많은 휴대 전화에서이 구현을 보았습니다 (예 : Sony의 Timescape UI). 해결 방법을 제안하십시오! 당신의 도움을 주셔서 감사합니다! 당신의 확인란이 문제를 일으키는 것처럼 사용자 정의 레이아웃의 당신의 체크 상자에

답변

1

사용자 지정 ListView 및 onItemClick 이벤트를 수행 할 때마다 사용자 지정 레이아웃 UI 요소에 대해이 속성을 설정해야합니다. 텍스트 뷰 및 체크 박스에 이렇게 설정하십시오.

android:focusable="false" 
android:focusableInTouchMode="false" 
+0

이러한 속성을 모든 개체에 추가해야합니까? listview와 체크 박스를 의미합니까? –

+0

예 모든 개체에 대해 설정해야합니다. – Piyush

2

설정이 ..

android:focusable="false" 
android:focusableInTouchMode="false" 

그래서 전체 코드는 다음과

<CheckBox 
    android:id="@+id/rowcheckBox1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/rowtext1" 
    android:layout_alignBottom="@+id/rowtext1" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="26dp" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:text="Select this" /> 

처럼 보일 것 같습니다. ..

+0

감사합니다! 너는 생명의 은인이야! 나는 그 체크 박스 xml에 그 줄들을 추가했다. 나를 위해 일했다! 그리고 확실하게 stackoverflow가 허용하는대로 대답을 받아 들일 것입니다 (5 분 후에 답을 받아 들일 수 있습니다! : D) –

+0

좋습니다. 다행이 당신을 도왔습니다. 해피 코딩. – InnocentKiller

관련 문제