Closed Shahar2k5 closed 9 years ago
I can't reproduce the error without more details.
mButton.setText("banana");
It's not sufficient, Please provide the entire code.
on the xml:
<mehdi.sakout.fancybuttons.FancyButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/startButton"
android:layout_centerHorizontal="true"
fancy:text="LET'S START"
fancy:borderColor="#FFFFFF"
fancy:borderWidth="1dp"
fancy:textColor="#FFFFFF" />
and in the activity:
mButton = (FancyButton) findViewById(R.id.startButton);
mButton.setText("banana");
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
Your code worked perfectly for me. Here is what i did
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this, yoService.class);
startService(i);
FancyButton mButton = (FancyButton) findViewById(R.id.startButton);
mButton.setText("test");
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.v("YO", "it Works");
}
});
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<mehdi.sakout.fancybuttons.FancyButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/startButton"
android:layout_centerHorizontal="true"
fancy:text="LET'S START"
fancy:borderColor="#FFFFFF"
fancy:borderWidth="1dp"
fancy:textColor="#FFFFFF" />
</RelativeLayout>
sett text via XML works OK but when trying to set text like this: mButton.setText("banana"); i get the following:
02-24 17:08:36.578 12189-12189/com.vidback.app E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams at android.widget.RelativeLayout$DependencyGraph.findRoots(RelativeLayout.java:1723) at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1670) at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:382) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:403) at android.view.View.measure(View.java:16831) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:16831) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:16831) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2586) at android.view.View.measure(View.java:16831) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2189) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1352) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1535) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791) at android.view.Choreographer.doCallbacks(Choreographer.java:591) at android.view.Choreographer.doFrame(Choreographer.java:561) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) at dalvik.system.NativeStart.main(Native Method)