I have cardview and material textview used inside LinearLayout layout like below
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:weightSum="2">
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_date"
android:layout_width="0dp"
android:clickable="true"
android:layout_weight="1"
android:layout_marginEnd="2dp"
android:layout_height="match_parent"
android:clipToPadding="true"
app:cardCornerRadius="5dp"
android:focusable="true">
<com.google.android.material.textview.MaterialTextView
android:layout_weight="1"
android:id="@+id/editText_schedule_date"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="@color/transparent"
android:text="@string/date_post"
android:focusableInTouchMode="false"
android:singleLine="true"
android:textColor="@color/textView_hint_upload"
android:theme="@style/editText_style"
android:textSize="16sp" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_marginStart="2dp"
android:layout_height="match_parent"
android:clipToPadding="true"
app:cardCornerRadius="5dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText_schedule_time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/transparent"
android:hint="@string/time_post"
android:gravity="center"
android:inputType="time"
android:singleLine="true"
android:textColor="@color/textView_upload"
android:textColorHint="@color/textView_hint_upload"
android:theme="@style/editText_style"
android:textSize="16sp" />
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
I am trying to use it in my activity like below
private MaterialCardView card_date;
then on create like below
card_date = findViewById(R.id.card_date);
card_date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("called","this card");
}
});
But its not working. I have tried textview onclick listener as well and that also not working. Let me know if anyone can help me for solve the puzzle. Thanks! Code outside this LinearLayout is working fine for same. Thanks!
I was have used
android:layout_weight="1"
in textview which was causing issue. I have removed it and it has been solved. Thanks!