Im having trouble to make work the viewflipper. I created a xml layout file view_flipper.xml :
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/MainView" layout="@layout/gallery_1" />
<include android:id="@+id/SearchView" layout="@layout/search_internal" />
</ViewFlipper>
the layout gallery_1 is just a ListView. the layout search_internal has an edittext, a button, and a listview.
Im using :
ViewFlipper theFlipper=(ViewFlipper) findViewById(R.id.flipper);
theFlipper.setDisplayedChild( R.id.SearchView );
to change the layout, but 开发者_如何学运维its apparently work for the code, but on the display, nothing is happening... Can someone help ?
Here is the code of the layout search_internal :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SearchBox"
>
<EditText android:text=""
android:id="@+id/QueryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="100px"
></EditText>
<Button android:layout_height="wrap_content"
android:id="@+id/BtnOk"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/searchBtnTxt"
android:clickable="true"></Button>
</LinearLayout>
<ListView
android:id="@+id/list_view_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/SearchBox"
android:background="#FFFFFF"
android:cacheColorHint="#FFFFFF"
android:layout_marginBottom="65dip"
android:gravity="top"
/>
</RelativeLayout>
I've found that I was not using correctly the function setDisplayedChild. setDisplayedChild is zero based index apparently. Sorry.
theFlipper.setDisplayedChild( 0 );
精彩评论