0
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/home_subscribe_card" 
    android:layout_width="match_parent" 
    android:layout_height="72dp" 
    android:onClick="@{vm.onGoalPress}" 
    card_view:cardCornerRadius="4dp"> 

<android.support.v7.widget.RecyclerView 
       android:id="@+id/feeds_list" 
       android:layout_width="200dp" 
       android:layout_height="30dp" 
       android:layout_marginTop="6dp" /> 

</CardView> 

클릭하면 카드보기가 작동하지만 리사이틀보기 영역을 클릭 할 수 없습니다. 카드보기 이벤트가 캡처되도록 클릭을 어떻게 할 수 있습니까?카드보기에서 리사이클 러보기를 클릭 할 수있게하십시오.

+0

당신의 질문은 명확하지 않습니다. 당신은 리사이클 러 뷰의 일부로 cradview를 추가하려고하지만 리사이클 러 뷰와 동일한 뷰 그룹에서 그것을 선언하려고합니다. 리사이틀 러 뷰 어댑터의 일부로 카드보기를 포함해야합니다. – Akshay

답변

0
public class InterceptTouchCardView extends CardView { 

public InterceptTouchCardView(Context context) { 
    super(context); 
} 

public InterceptTouchCardView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public InterceptTouchCardView(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
} 

/** 
* Intercept touch event so that inner views cannot receive it. 
* 
* If a ViewGroup contains a RecyclerView and has an OnTouchListener or something like that, 
* touch events will be directly delivered to inner RecyclerView and handled by it. As a result, 
* parent ViewGroup won't receive the touch event any longer. 
*/ 
@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    return true; 
} 

}

0

recylerview의 경우 listview와 같이 clickable을 사용하려면 어댑터 순서를 설정해야합니다. 당신은 링크를 참조 할 수 있습니다 : https://developer.android.com/training/material/lists-cards.html 당신은 여기에 또 다른 질문보고 수행 할 수 있습니다 Why doesn't RecyclerView have onItemClickListener()? And how RecyclerView is different from Listview?

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.my_activity); 
    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); 

    // use this setting to improve performance if you know that changes 
    // in content do not change the layout size of the RecyclerView 
    mRecyclerView.setHasFixedSize(true); 

    // use a linear layout manager 
    mLayoutManager = new LinearLayoutManager(this); 
    mRecyclerView.setLayoutManager(mLayoutManager); 

    // specify an adapter (see also next example) 
    mAdapter = new MyAdapter(myDataset); 
    mRecyclerView.setAdapter(mAdapter); 
} 
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { 
private String[] mDataset; 

// Provide a reference to the views for each data item 
// Complex data items may need more than one view per item, and 
// you provide access to all the views for a data item in a view holder 
public static class ViewHolder extends RecyclerView.ViewHolder { 
    // each data item is just a string in this case 
    public TextView mTextView; 
    public ViewHolder(TextView v) { 
     super(v); 
     mTextView = v; 
    } 
} 

// Provide a suitable constructor (depends on the kind of dataset) 
public MyAdapter(String[] myDataset) { 
    mDataset = myDataset; 
} 

// Create new views (invoked by the layout manager) 
@Override 
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, 
               int viewType) { 
    // create a new view 
    View v = LayoutInflater.from(parent.getContext()) 
          .inflate(R.layout.my_text_view, parent, false); 
    // set the view's size, margins, paddings and layout parameters 
    ... 
    ViewHolder vh = new ViewHolder(v); 
    return vh; 
} 

// Replace the contents of a view (invoked by the layout manager) 
@Override 
public void onBindViewHolder(ViewHolder holder, int position) { 
    // - get element from your dataset at this position 
    // - replace the contents of the view with that element 
    holder.mTextView.setText(mDataset[position]); 

} 

// Return the size of your dataset (invoked by the layout manager) 
@Override 
public int getItemCount() { 
    return mDataset.length; 
} 

}이 //holder.mTextView.setOnClickListener(onClick 같은

가 // 뭔가를)

+0

자세히 설명해 주시겠습니까? 어댑터 주문은 무엇을 의미합니까? – zooney

+0

안녕 나는 다만 응답을 편집한다. 이것을 봐주세요. –

0

recyclerview 어댑터의 뷰 소유자 내에 클릭 리스너를 설정해야합니다. Viewholder 내에서 모든 뷰의 모든 요소, 즉 recyclerview가 부양하는 layoyt의 Viewgroup에 액세스 할 수 있습니다. 나는 그것이 의미가 있기를 바랍니다.

또는 onBind() 메서드에서 onclick 수신기를 설정할 수 있습니다. 당신의 cardview는 다음에 액세스 할 수있는 직접적인 방법이없는 외부 재활용보기 인 경우

당신은 this question

좀 걸릴 수 있습니다. 당신이 당신의 카드보기를 팽창되는 경우 활동/조각으로 재활용 뷰에서 콜 백업 또는 이벤트 버스를 사용하고 "InterceptTouchCardView"와 새로운 값

+0

리사이클 러 뷰를 클릭하면 카드보기의 클릭 이벤트를 캡처하고 싶습니다. – zooney

+0

@zooney 나는 내 친구들을 업데이트했다. 보세요 – Akshay

0

soulution와 카드보기를 업데이트 RecyclerView의 항목에 클릭 가능한보기 (예 : 버튼)가있을 때 문제가 발생합니다. 이러한 클릭 가능한 뷰에는 터치 이벤트가 전혀 발생하지 않습니다. 더 나은 soulution는 RecyclerView을 확장하고 onInterceptTouchEvent와 onTouchEvent를 오버라이드 (override)하는 것입니다, 그래서 그들은 모두 그냥이 (코 틀린 구문)처럼 false를 반환 :

class ClickThroughRecyclerView : RecyclerView { 

    constructor(context: Context) : super(context) 

    constructor(context: Context, attr: AttributeSet?) : super(context, attr) 

    constructor(context: Context, attr: AttributeSet?, defStyle: Int) : super(context, attr, defStyle) 

    override fun onInterceptTouchEvent(e: MotionEvent): Boolean { 
     return false 
    } 

    override fun onTouchEvent(e: MotionEvent): Boolean { 
     return false 
    } 

} 

를 레이아웃 파일 내부에 ClickThroughRecyclerView을 사용하여, 그 터치 이벤트가에 의해 소비되지 보장 RecyclerView의 항목 (버튼 등)은 RecyclerView의 부모보기로 전달됩니다.

관련 문제