2011-09-13 58 views
0

我想动态添加视图切换器。Android - 视图切换器

ViewSwitcher switcher = new ViewSwitcher(this); 

如何将两个布局添加到视图切换器并使用代码切换视图?

错误:

A1 [Android Application]  
DalvikVM[localhost:8604] (may be out of synch) 
    Thread [<1> main] (Suspended (exception RuntimeException)) 
     ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1815  
     ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1831 
     ActivityThread.access$500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 122  
     ActivityThread$H.handleMessage(Message) line: 1024 
     ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
     Looper.loop() line: 132 
     ActivityThread.main(String[]) line: 4123  
     Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
     Method.invoke(Object, Object...) line: 491 
     ZygoteInit$MethodAndArgsCaller.run() line: 841 
     ZygoteInit.main(String[]) line: 599 
     NativeStart.main(String[]) line: not available [native method] 
    Thread [<8> Binder Thread #2] (Running) (may be out of synch) 
    Thread [<7> Binder Thread #1] (Running) (may be out of synch) 
    Thread [<9> SoundPool] (Running) (may be out of synch) 
    Thread [<10> SoundPoolThread] (Running) (may be out of synch) 
+0

你能在这里添加一些代码。还需要一些更多的日志记录,因为这种异常似乎是实际异常的结果。 – Ronnie

回答

0

请参阅ViewSwitcherAndroid documentation。您可以根据需要使用addView()showNext()方法。

呼叫addView两次指数在0和1

addView(child, index, 
      new ViewGroup.LayoutParams(
        LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 

这应该没有问题工作..

+0

这不起作用,只是崩溃的应用程序 – JeffLemon

+0

添加完整的错误日志.. – Ronnie