내 자신의 버전의 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). 해결 방법을 제안하십시오! 당신의 도움을 주셔서 감사합니다! 당신의 확인란이 문제를 일으키는 것처럼 사용자 정의 레이아웃의 당신의 체크 상자에
이러한 속성을 모든 개체에 추가해야합니까? listview와 체크 박스를 의미합니까? –
예 모든 개체에 대해 설정해야합니다. – Piyush