这甚至可能吗?我创建了这个视图鳍状肢,我从xml布局的onClick内部调用视图鳍状肢。我以前创建了一个视图鳍状肢,但由于某种原因它不起作用。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:cacheColorHint="@android:color/transparent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vf_sample1_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
<include layout="@layout/headers_main" />
<include layout="@layout/searchbar" />
<TextView
android:id="@+id/sdfsd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:maxHeight="85dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
onClick="gotoSomething"
android:singleLine="false" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/aquablue"
android:textSize="15dp"
android:textStyle="bold" />
<include layout="@layout/listview_item_row_now_playing_info" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/aquablue"
android:textSize="15dp"
android:textStyle="bold" />
<include layout="@layout/container_listview" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vf_sdfsdfadf"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@null"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
<include layout="@layout/header_vf_asdfasdfadadafsd" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vf_adsfasdfadsfasd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@null"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
</LinearLayout>
</ViewFlipper>
</LinearLayout>
代码:
public class BeatSpotPrototypeActivity extends BaseListActivity {
private final String TAG = BeatSpotPrototypeActivity.class.getSimpleName();
private ApplicationStateManager mAppStateMananger = ApplicationStateManager.GetInstance();
private Context mCtx = null;
private boolean mIsInitalized = false;
private boolean mDataChanded= false;
private ViewFlipper mViewFlipper= null;
private DrawableManager mDrawManager = new DrawableManager();
private enum ViewFlipperModes {
MAIN (0),
NOW_PLAYING (1),
SONG_INFORMATION (2);
private final int index;
ViewFlipperModes(int index) {
this.index = index;
}
public int index() {
return index;
}
}
</code>
<code>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_beatspot_activity);
if (!mIsInitalized)
init();
else
mDataChanded = true;
showLoading(false);
}
private void init() {
mCtx = this;
mIsInitalized = true;
mViewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper);
fadeDrawables();
}
public void gotoBeatspotMain(View v) {
mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index());
}
public void gotoNowPlaying(View v) {
Log.d(TAG, mViewFlipper.getCurrentView().toString());
mViewFlipper.setDisplayedChild(ViewFlipperModes.NOW_PLAYING.index());
}
public void gotoSongDetails(View v) {
mViewFlipper.setDisplayedChild(ViewFlipperModes.SONG_INFORMATION.index());
Log.d(TAG, String.valueOf(ViewFlipperModes.SONG_INFORMATION.index()));
}
}
答案 0 :(得分:3)
setDisplayedChild
采用索引,而非id。
答案 1 :(得分:1)
ViewFlipper mViewFlipper = (ViewFlipper)findViewbyId(location);
确保setcontentView(R.layout.something)上的任何布局 确实包含视图鳍状肢
也试试这个。在此行之前mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index()); 输入:
int i = (ViewFlipperModes.MAIN.index()); place a debug point here
mViewFlipper.setDisplayedChild(i);
我还建议使用调试器来确定是否在调试器中调用了翻转视图事件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/book_as_whole_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<ViewFlipper
android:layout_marginTop="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ViewFlipper">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/page1"
android:text="@string/loading_string"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:typeface="serif"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/page2"
android:text="@string/loading_string"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:typeface="serif" />
</LinearLayout>
</ViewFlipper>
</LinearLayout>