0
私はアンドロイドでイントロ画面に関する問題に直面しています。 私は1つの断片でbutton
を作成するが、私は活動にlayoutinflate
を通じてwelcomeActivity
にこのボタンを呼び出すようにしようとしているが、それは任意の機能を実行しません。紹介画面ボタンViewPager
XMLフラグメント(custom_intro):WelcomeActivityLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id ="@+id/explore"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Explore"
android:background="@drawable/round_button"
android:padding="15dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="114dp" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">
<!--tools:showIn="@layout/welcome_activity"-->
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
WelcomeActivityJava:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_activity);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
customView = inflater.inflate(R.layout.custom_intro, null);
Button button=(Button)customView.findViewById(R.id.explore);
button.setText("Test");
Int[] layouts = new int[]{
R.layout.custom_intro,
R.layout.custom_intro1,
R.layout.custom_intro2,
R.layout.custom_intro3,
R.layout.custom_intro4};
myViewPagerAdapter = new MyViewPagerAdapter();
viewPager.setAdapter(myViewPagerAdapter);
viewPager.addOnPageChangeListener(viewPagerPageChangeListener);
viewPagerIndicator.setupWithViewPager(viewPager);
viewPagerIndicator.addOnPageChangeListener(viewPagerPageChangeListener);
}
私はあなたが現在のフラグメントから別のフラグメントを呼び出したい場合は、このボタン –
を介して第2の断片を呼び出したい場合はどのような\t \t \t 公共ボイドcallNextFragment(){ NextFragment nextFrag =新しいNextFragment()。 (null) getActivity()。getSupportFragmentManager()。beginTransaction() 。 } –
親アクティビティからこのメソッドを呼び出します –