Tôi sử dụng ListView để hiển thị một số mục. row.xml tôi như sau:Nhận vị trí trong ListView
<TextView android:text="text"
android:id="@+id/tvViewRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<Button android:text="Click me!"
android:id="@+id/BtnToClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClick">
</Button>
Và tôi xác định myClick trong Hoạt động như sau:
public void myClick (View v) {
LinearLayout vwParentRow = (LinearLayout)v.getParent();
//How to get the position
}
Làm thế nào để biết vị trí mà buttom được bấm? Vị trí có nghĩa là giống như phương thức onListItemClick's.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
}
Câu hỏi này đã được hỏi trước đó, hãy nhìn lên câu hỏi trước đăng. – JoxTraex