onItemClick을 사용할 때 vursor 어댑터가 표시하는 항목 목록이 있습니다. 올바른 행을 가져와 필요한 항목을 수행 할 수 있습니다 (내 목표는 해당 항목에보기를 추가하는 것입니다.) 지금이 작업이 필요합니다. listView 셀의 단추를 클릭하는 동안 발생합니다. 그러나 단추 클릭 이벤트는 올바른 셀을 반환하지 않지만 목록의 임의의 다른 셀을 반환합니다. 여기에 내 코드 예제가 있습니다. 내가 할 수 셀에있는 버튼을 클릭 원하는이 샘플 코드에서 커서 어댑터의 클릭 이벤트 사용
public class CustumAdapter extends CursorAdapter implements OnClickListener{
private Context context;
private Button btn_maybe;
private String name;
public CustumAdapter(Context context, Cursor c, LatLng position) {
super(context, c);
this.position = position;
this.context = context;
}
@Override
public void bindView(View view, final Context context, Cursor c) {
name = c.getString(c.getColumnIndex(ContractPlaces.PLACE_NAME));
btn_maybe = (Button) view.findViewById(R.id.cursor_layout_maybe);
btn_maybe.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//i need to use the correct view from BindView here
}
});
nameView.setText(name);
나 내가 올바른 세포를 얻을 수있는 방법, 버튼 정말, 그러나 나는 다시 무작위 목록 세포에서보기를 얻을 수있는 뷰를 accsses inf 내 클릭 수신기에서?
편집
: 커서 어댑터의 클릭 이벤트를 사용하여 목록 항목에 대한보기를 얻기 위해, 내가 그것을 알아 냈 @darnmason하는
너무 감사합니다, 질문 커서있을 것입니다 태그의 버튼을 설정합니다. 하는 getPosition(), 태그가 목록보기 라이프 사이클의 진정한 본질에있는 항목의 정확한 위치는, 그래서 내가 특정 위치에있는 항목의보기를 원한다면 당신이 공제 할 때, 내가
//where lv is the ListView (you can pass it to the adapter as a parameter).
//getChildAt returns a view in a position
//value is the value of cursor.getPosition() so its the correct position of the item where //the button was clicked.
//lv.getFirstVisiblePosition() is the first position that is actually on screen,
View view = lv.getChildAt(value - lv.getFirstVisiblePosition());
를 호출합니다 실제 위치에서 필요한 위치를 얻으려면 추가하는 것을 잊지 마십시오.
01 exeptions을 피하기 위해
내 문제는 onClickListener입니다. 저는 버튼의 뷰만 가져 왔고 bindView와 같은 전체 셀 뷰가 필요합니다. –
bindView의 버튼에 태그를 설정한다는 의미이므로 onClick에서 태그 – darnmason
의 인덱스를 가져옵니다. 예! 저것은 일했다! 고마워! –