I have a TextView
which contains onclick
in xml.The onclick works sometimes and sometimes the app crashes.I renamed the TextView
in xml to android.support.v7.widget.AppCompatTextView
,but it didn't solved the issue.I found similar questions but none of solved mine.
code
public void customerDetails(View view){
Intent intent=new Intent(Customers.this,CustomerDetails.class);
intent.putExtra(Common.CUSTOMERID,view.getTag().toString());
startActivity(intent);
}
My XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
app:cardCornerRadius="4dp"
app:cardElevation="1dp"
app:cardMaxElevation="0dp"
app:cardUseCompatPadding="true"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/customer_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/call_button"
android:layout_toLeftOf="@+id/amount"
android:layout_toRightOf="@+id/call_button"
android:layout_toStartOf="@+id/amount"
android:onClick="customerDetails"
android:text="Customer Name"
android:textColor="@color/colorAccent"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/customer_name"
android:text="ContactPersonName"
android:textColor="@color/primary_text"
android:textSize="12sp"
android:id="@+id/contact_person_name"
android:layout_toLeftOf="@+id/amount"
android:layout_toStartOf="@+id/amount"
android:layout_toRightOf="@+id/call_button"
android:layout_toEndOf="@+id/call_button"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Error is
java.lang.IllegalStateException: Could not find method customerDetails(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatTextView with id 'customer_name'