В настоящее время я работаю над простым приложением для Android.Android: Как найти, какая вкладка активна в tablayout?
Существует страница входа в систему, и, поскольку вы можете войти в систему как драйвер или как пассажир, на этой странице есть разные вкладки.
я должен использовать один и тот же «электронная почта» и «пароль ПОЛЕЙ и ту же кнопку входа. В основном единственное, что изменение является подзаголовок
Мне нужно, чтобы выяснить, какие вкладки . активна, когда кнопка нажата Войти, чтобы использовать правильные параметры входа в систему и отправить пользователю в нужное место
Вот часть кода:
Войти раскладка:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.domain.myname.schoolproject.Login_Screen">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/Nom_Application"
android:id="@+id/txtTitle"
android:textAlignment="center"
android:textColor="#010101"
android:textSize="45sp"
android:textStyle="bold"
android:autoText="false"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/Connexion"
android:id="@+id/txtSubtitle"
android:layout_marginTop="20dp"
android:textColor="#010101"
android:textSize="18sp"
android:textIsSelectable="false"
android:textStyle="bold"
android:layout_below="@+id/txtTitle"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="@+id/imgLeft"
android:src="@drawable/carleft"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="70dp"
android:contentDescription="@string/Description_icône" />
<ImageView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="@+id/imgRight"
android:src="@drawable/carright"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/imgLeft"
android:contentDescription="@string/Description_icône"
android:layout_alignParentStart="false" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_below="@+id/imgLeft" />
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:layout_alignTop="@+id/toolbar" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_weight="1"
android:background="@android:color/white"
android:layout_below="@+id/sliding_tabs"
android:layout_alignBottom="@+id/edtPassword" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/edtMail"
android:hint="@string/Mail"
android:textSize="20dp"
android:textIsSelectable="true"
android:layout_alignLeft="@+id/edtPassword"
android:layout_alignStart="@+id/edtPassword"
android:layout_marginTop="20dp"
android:layout_above="@+id/edtPassword" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/edtPassword"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:elegantTextHeight="false"
android:hint="@string/Password"
android:textSize="20dp"
android:textIsSelectable="false"
android:layout_above="@+id/btnConnexion"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Inscription"
android:id="@+id/btnInscription"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:background="#0006ff"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_alignParentEnd="true"
android:onClick="onInscription" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/title_activity_login_screen"
android:id="@+id/btnConnexion"
android:background="#15c100"
android:textSize="20dp"
android:layout_above="@+id/btnInscription"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:textColor="#ffffff"
android:onClick="onConnexion"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/txtError"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textColor="#d60c00"
android:singleLine="false" />
</RelativeLayout>
Один из макетов фрагментов
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.domain.myname.schoolproject.Login_Screen">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/Driver"
android:id="@+id/txtSubtitle"
android:textColor="#010101"
android:textSize="18sp"
android:textIsSelectable="false"
android:textStyle="bold"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Класс pageAdapter
public class PageAdapter extends FragmentPagerAdapter {
private Context context;
public PageAdapter(FragmentManager fm, Context context) {
super(fm);
this.context=context;
}
public Fragment getItem(int pos) {
switch (pos) {
case 0:
return new LoginDriver();
case 1:
return new LoginPassenger();
}
return null;
}
public int getCount() {
return 2;
}
public CharSequence getPageTitle(int pos) {
switch (pos) {
case 0:
return context.getApplicationContext().getResources().getString(R.string.Driver);
case 1:
return context.getApplicationContext().getResources().getString(R.string.Passenger);
}
return null;
}
}
А из класса LoginScreen, мне нужно узнать текущую вкладку в этом случае
public void onConnexion(View view) {
android.content.Intent getNextScreen;
String mail = txtMail.getText().toString();
String pass = txtPass.getText().toString();
//Identification(this.)
getNextScreen = new android.content.Intent(this, Summary_Driver_Screen.class);
startActivity(getNextScreen);
}
Большое спасибо за помощь. При необходимости я могу предоставить более подробную информацию.
getSelectedTabPosition не существует. мне нужно использовать something.getSelectedTabPosition? –
Это метод вашего 'TabLayout' – ianhanniballake
Как получить tabname из выбранного значения –