Androidプログラミングは初めてで、誰かが私を助けてくれることを願っています: 1.私はここのデモの1つからコーディングしています: http://developer.android.com/training/animation/screen-slide.html
メインの activity_screen_slide.xml ファイルがあります。
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.ViewPager>
別の xml ファイル main.xml には、いくつかのボタンがあります。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Main" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <Button android:id="@+id/buttonStart" android:text="test"/> </LinearLayout>
メインの Java アクティビティ ファイル内で、コンテキストは次のように設定されます。
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_slide);
testButton のリスナーを設定しようとすると、設定できません。これは、その後 (別の Java ファイルのインフレータを介して) ボタンが生成されたときに、ボタンをクリックしても応答がないことを意味します。
インフレータを生成する Java ファイルは次のとおりです。
ViewGroup rootView;
rootView = (ViewGroup) inflater.inflate(R.layout.main, container, false);
ありがとう、あなたの助けに感謝します
乾杯D