开发者

Android - view Switcher

I want to add a view switcher dynamically.

  ViewSwitcher switcher = new ViewSwitcher(this);

How do I add my two layouts to the view switcher and switch between views using code?

Errors:

A1 [Android Application]    
DalvikVM[localhost:8604] (may be out of synch)  
    Thread [<1> main] (Suspended (exception RuntimeException))  
    开发者_JAVA技巧    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)   


http://developer.android.com/reference/android/widget/ViewSwitcher.html

Public Methods

void     addView(View child, int index, ViewGroup.LayoutParams params)

Adds a child view with the specified layout parameters.


Refer the Android documentation of ViewSwitcher. You can use the addView() and showNext() methods for your needs.

Call addView twice with indexes 0 and 1.

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

This should work without problems..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜