package com.android.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ViewFlipper; public class AndroidTestActivity extends Activity { private ViewFlipper viewFlipper; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1); } public void MyOnClickButtonNext(View v) { viewFlipper.showNext(); } public void MyOnClickButtonPrevious(View v) { viewFlipper.showPrevious(); } public void MyOnClickButtonTherd(View v) { viewFlipper.setDisplayedChild(2); } }
<?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:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="メイン画面" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="MyOnClickButtonPrevious" android:text="戻る" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="MyOnClickButtonNext" android:text="次へ" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="MyOnClickButtonTherd" android:text="第三画面" /> </LinearLayout> <ViewFlipper android:id="@+id/viewFlipper1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <include android:id="@+id/firstlayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" layout="@layout/first" /> <include android:id="@+id/secondlayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" layout="@layout/second" /> <include android:id="@+id/thirdlayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" layout="@layout/third" /> </ViewFlipper> </LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一画面" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/vermeer02" android:layout_gravity="center_horizontal"/> </LinearLayout>
参考:
You must specifiy a valid layout reference. The layout ID @layout/xxx と表示された場合、
Eclipseを再起動させる。
0 件のコメント:
コメントを投稿