I 인해 루프,이 솔루션의 매우 자랑스럽게 아니지만,이 짧은 목록에 대한 대안입니다 :
할 수 있습니다 리스너, 뷰 및 어댑터에서 viewHolder에서 클릭보기를 얻을
Use this method
/**
* Returns the adapter position of the Child associated with this ChildViewHolder
*
* @return The adapter position of the Child if it still exists in the adapter.
* RecyclerView.NO_POSITION if item has been removed from the adapter,
* RecyclerView.Adapter.notifyDataSetChanged() has been called after the last
* layout pass or the ViewHolder has already been recycled.
*/
@UiThread
public int getChildAdapterPosition() {
int flatPosition = getAdapterPosition();
if (mExpandableAdapter == null || flatPosition == RecyclerView.NO_POSITION) {
return RecyclerView.NO_POSITION;
}
return mExpandableAdapter.getChildPosition(flatPosition);
}
Also see
: 뷰 홀더 위치, 결국이 방법을 사용하여
리스너를 정의하는 쉬운 방법 here.
ItemClickSupport.addTo(mRecyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
// do it
}
});
사용 this는 viewHolder를 얻을 수 있습니다 :
@Override
public void onClick(View v) {
MyHolder holder = (MyHolder) mRecyclerView.getChildViewHolder(v);
holder.textView.setText("Clicked!");
}
가 view typeknow when의 클릭 뷰가 부모 또는 "버튼을 클릭 리스너"당신이 얻을를 사용하여 아이
//Returns the view type of the item at position for the purposes of view recycling.
@Override
public int getItemViewType(int position) {
if (items.get(position) instanceof User) {
return USER;
} else if (items.get(position) instanceof String) {
return IMAGE;
}
return -1;
}
입니다 확인 보기 및보기 소유자와 어댑터 위치를 표시합니다. 매우 긴 목록이 아니라면 첫 번째 위치에서 클릭 한 위치까지 반복 할 수 있습니다 (parent? count = 0 : count ++). count는 루프 이후의 하위 위치입니다. 자신의 코드를 확인하면 동일한 기능을 수행하는 곳을 찾을 수 있습니다. – albodelu