내 listview에 체크 박스, textviews 및 imageview가 있습니다. 항목을 클릭하면 onclicklistnere가 작동하지 않습니다. 확인란이 자체 리스너를 가지고 있으며 listview onclicklistener를 재정의하기 때문에이 사실을 알고 있습니다. 벌금. 내가 체크 박스에안드로이드리스트보기 onclicklistener가 체크 박스와 함께 작동하지 않습니다.
android:focusable="false"
android:focusableInTouchMode="false"
을 설정할 때, 나는 목록 항목을 클릭 할 수 있지만, 체크 박스 (아이템 등)뿐만 아니라 오렌지를 becames.
반식법이므로 누구보다 나은가요?
public class ListViewTutorial2Activity extends Activity {
SimpleAdapter mSchedule;
ListView list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list = (ListView) findViewById(R.id.SCHEDULE);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("train", "101");
map.put("from", "6:30 AM");
map.put("to", "7:40 AM");
mylist.add(map);
map = new HashMap<String, String>();
map.put("train", "103(x)");
map.put("from", "6:35 AM");
map.put("to", "7:45 AM");
mylist.add(map);
mSchedule = new SimpleAdapter(this, mylist, R.layout.row,
new String[] {"train", "from", "to"}, new int[] {R.id.TRAIN_CELL, R.id.FROM_CELL, R.id.TO_CELL});
list.setAdapter(mSchedule);
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = list.getItemAtPosition(position);
}
});
}
}
및 row.xml : 당신은이 작업을 수행하는 확인란에 특별한 속성을 설정할 필요가 없습니다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:descendantFocusability="beforeDescendants">
</CheckBox>
<TextView android:id="@+id/TRAIN_CELL"
android:layout_width="50dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/FROM_CELL"
android:layout_width="70dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="@+id/TO_CELL"
android:layout_width="60dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<ImageView
android:id="@+id/icon"
android:layout_width="22px"
android:layout_height="22px"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:layout_marginTop="4px"
android:src="@drawable/icon" >
</ImageView>
</LinearLayout>
에 대한
onStateChangedListener
을했기 때문에 내 문제는 것을 깨달았다 확인란이를 추가 할 때 – erdomesterListViews 및 ExpandableListViews를 그런 식으로 처리하면 안됩니다 (항목에 직접 액세스하려고 시도). 대신 사용자 정의 ListAdapter (예 : extends SimpleAdapter)를 만들고 .getView() 메소드를 재정의해야합니다. 사용자 정의 버전의 .getView() 메소드에서 CheckBox (즉, view.findViewById (R.id.itemcheckbox))의 하위보기에서 로컬 검색을 수행하고 거기에 OnClickListener를 설정할 수 있습니다. ListView는 다른 항목에 대해 Views를 재사용하므로 이러한 방식으로 ListView와 해당 하위보기를 처리해야합니다. – straya
이 설명에 대한 귀하의 대답을 수락합니다.감사. 나는 나의 문제를 마침내 풀 수 있었다. 그러나 그것은 쉽지 않았다. – erdomester