support - switchcompat android example
SwitchCompat error de lanzamiento (1)
Estoy tratando de usar switchcompat en mi fragmento. La API mínima soportada es 14 y la máxima es 21. Estoy tratando de aplicar la vista de material para cambiar todas las versiones de Android anteriores a la piruleta. Pero cuando uso el siguiente código, aparece un error: ¿Cómo puedo corregirlo?
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Inflando en el código java que está lanzando la excepción:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_scheduler_ui, container, false);
Referencia: http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html
Excepción:
10-24 14:15:15.880 1561-1561/com.stackoverflow.ranjith.androidprojdel E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.stackoverflow.ranjith.androidprojdel, PID: 1561
java.lang.NullPointerException
at android.text.Layout.getDesiredWidth(Layout.java:67)
at android.support.v7.widget.SwitchCompat.makeLayout(SwitchCompat.java:570)
at android.support.v7.widget.SwitchCompat.onMeasure(SwitchCompat.java:495)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Build.gradle:
dependencies {
compile ''com.android.support:cardview-v7:+''
compile ''com.android.support:recyclerview-v7:+''
compile ''com.android.support:palette-v7:+''
compile ''com.android.support:support-v4:+''
compile "com.android.support:appcompat-v7:21.0.+"
compile fileTree(dir: ''libs'', include: [''*.jar''])
}
SwitchCompat
requiere que establezca los valores de android:textOn
y android:textOff
menos que configure app:showText="false"
:
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="ON"
android:textOff="OFF" />
o (asumiendo que tiene xmlns:app="http://schemas.android.com/apk/res-auto"
en la parte superior de su archivo XML)
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:showText="false" />