Reputation: 379
I have a layout with three TextViews, two TextViews are responding to Click Events but the last one is not responding. I am using Navigation to navigate to other fragments. The OnClick method is called inside an adapter which implements view.OnClickListener.
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_marginStart="@dimen/defaultMargin"
android:layout_height="wrap_content">
<TextView
android:text="How CADO works"
style="@style/CircularBook"
android:drawableEnd="@drawable/arrow_right"
android:layout_width="0dp"
android:layout_height="@dimen/buttonHeight"
android:id="@+id/howCadoWorks"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<View
app:layout_constraintTop_toBottomOf="@id/howCadoWorks"
android:layout_width="match_parent"
android:background="@color/pinkishGray"
android:layout_height="0.5dp"
android:id="@+id/view3"></View>
<TextView
android:text="FAQ"
style="@style/CircularBook"
android:layout_width="0dp"
android:drawableEnd="@drawable/arrow_right"
android:layout_height="@dimen/buttonHeight"
android:id="@+id/faqs"
app:layout_constraintTop_toBottomOf="@+id/view3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<View
app:layout_constraintTop_toBottomOf="@id/faqs"
android:layout_width="match_parent"
android:background="@color/pinkishGray"
android:layout_height="0.5dp"
android:id="@+id/view4"></View>
<TextView
android:text="Contact Us"
android:drawableEnd="@drawable/arrow_right"
style="@style/CircularBook"
android:layout_width="0dp"
android:layout_height="@dimen/buttonHeight"
android:id="@+id/contactus"
app:layout_constraintTop_toBottomOf="@+id/view4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
OnClickMethod
public void onClick(@Nullable View view) {
NavController var3 = Navigation.findNavController(view);
if(view.getId()==R.id.contactus){
**var3.navigate(R.id.contactus_fragment);**
return;
}
else if (view.getId()==R.id.faqs){
var3.navigate(R.id.faqFragmnt);
return;
}
else if (view.getId()==R.id.howCadoWorks){
Toast.makeText(view.getContext(),"Feature is in Progress", Toast.LENGTH_SHORT).show();
// var3.navigate(R.id.contactus_fragment);
return;
}
else
{
}
}
I have tried multiple ways, rechecked id's as well but nothing is working.
Upvotes: 2
Views: 162
Reputation: 1332
as @Nilesh Rathod said, you need to make sure that all your text view have set an on click listener like:
textView.setOnClickListener(this);
or you can also:
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Here you put the code you want to use for the specific textView click event
}
});
Upvotes: 5