0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="10dp"
android:paddingTop="8dp"
android:descendantFocusability="blocksDescendants">



<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_gravity="center_horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="2dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <View
            android:id="@+id/view"
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:background="@color/accent"/>


        <TextView
            android:id="@+id/m_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FF6600"
            android:textSize="30dp"
            android:layout_toRightOf="@id/view"
            android:text="hey th"
            android:textStyle="bold" />

        <Button
            android:id="@+id/m_delete"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_toRightOf="@id/m_name"
            android:layout_weight="0"
            android:text="Delete" />


    </RelativeLayout>


</android.support.v7.widget.CardView>

I have put a button inside like this and this is shown in recycler view. The problem I am facing is that the button click only works if I long press on the button else if i click normally then intent is called.

    holder.delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MetricsDAO dao = new MetricsDAO(context);
            dao.deleteMetrics(metrices.get(position).getEventName());
            dao.close();

            Intent i = new Intent(context, HealthGraph.class);
            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
            // ((Activity) context).finish();

        }
    });

I am doing this inside on onBindViewHolder().. What is it that i am doing wrong or missing?

bhaskar
  • 991
  • 1
  • 15
  • 37
  • check this link will help you [link](http://stackoverflow.com/questions/28379302/add-clicklistner-for-button-inside-a-cardview-populated-using-a-recyclerview) – sud Nov 27 '15 at 07:03
  • Thanks but I have done the same thing and it still does not work :( – bhaskar Nov 27 '15 at 08:35

0 Answers0