プロジェクトでビュースイッチャーを使用しています。
私の xml では、すべて同じ ID を持つ 2 つのレイアウトを作成しました。ビューを切り替えた後、両方のレイアウトで同じ ID を使用しているため、前のビューに切り替えることができません。
ビュースイッチャーの両方のレイアウトに対してJavaコードで1つのリスナーを使用するにはどうすればよいですか。別のIDを作成して、別のリスナーを作成して再度切り替えることはしたくありません。
私のxmlは以下の通りです。
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/profileSwitcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/hello_world" />
<Button
android:id="@+id/switchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Switch" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/hello_world" />
<Button
android:id="@+id/switchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Switch" />
</RelativeLayout>
</ViewSwitcher>
私のJavaコードは次のとおりです
final ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.profileSwitcher);
Button btn = (Button) findViewById(R.id.switchBtn);
btn.setOnClickListener(new OnClickListener() {
private boolean switchCheck;
public void onClick(View v) {
new AnimationUtils();
switcher.setAnimation(AnimationUtils.makeInAnimation(getApplicationContext(), true));
if (!switchCheck) {
switcher.showNext();
switchCheck = true;
} else {
switcher.showPrevious();
switchCheck = false;
}
}
});
助けてください..