0
My goal is to have one Button
with 2 TextView
s inside. So I researched the easiest way is to have a LinearLayout
and inside place the TextView
s and place the property android:clickable="true"
.
The problem is that I can’t simulate the button action because I get an exception. Can someone help me?
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#D8D8D8"
android:orientation="vertical"
android:clickable="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/daily"
android:text="@string/daily"
android:textSize="14dp"
android:gravity="center_vertical|left"
android:onClick="OnClick"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hora"
android:textSize="10dp"
android:text="Hora"
android:gravity="center_vertical|left"/>
</LinearLayout>
In Java, I have this:
private void OnClick(View view){
DialogFragment newFragment = new PickerFragment();
newFragment.show(this.getFragmentManager(), "timePicker");
}
To Exception
that I’m getting is:
Process: com.converter.android.dailyhoroscope, PID: 7679
java.lang.IllegalStateException: Could not find method OnClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.TextView with id 'dailyHoroscope' at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4479) at android.view.View$DeclaredOnClickListener.onClick(View.java:4443) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I’ve already put the android:onClick="OnClick"
within the tag
of LinearLayout
and I keep getting the exception.
My problem is in Java the private way. It has to be public.
– porthfind
Or
protected
if you prefer.– Androiderson
Where have you rewritten this method onClick @porthfind? and can you be clearer on what you’re trying to achieve? maybe an illustration?
– dariodm