Java Android:如何在表格布局中找到哪个选项卡处于活动状态?
我目前正在开发一个简单的android应用程序 有一个登录页面,由于可以作为驾驶员或乘客登录,该页面中有不同的选项卡 我必须使用相同的“电子邮件”和“密码”字段a,以及相同的登录按钮。基本上唯一改变的是字幕 我需要确定当按下登录按钮时哪个选项卡处于活动状态,以便使用正确的登录选项并将用户发送到正确的位置 以下是部分代码: 登录布局:Java Android:如何在表格布局中找到哪个选项卡处于活动状态?,java,android,android-layout,android-fragments,Java,Android,Android Layout,Android Fragments,我目前正在开发一个简单的android应用程序 有一个登录页面,由于可以作为驾驶员或乘客登录,该页面中有不同的选项卡 我必须使用相同的“电子邮件”和“密码”字段a,以及相同的登录按钮。基本上唯一改变的是字幕 我需要确定当按下登录按钮时哪个选项卡处于活动状态,以便使用正确的登录选项并将用户发送到正确的位置 以下是部分代码: 登录布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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>
在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不存在。我必须使用什么。getSelectedTabPosition?这是一种f您的
TabLayout
如何获取tabselected@SanikaKadam-pagerAdapter.getPageTitle(tabLayout.getSelectedTabPosition())
use tab Selected Events getSelectedTabPosition不存在。我必须使用什么吗。getSelectedTabPosition?这是TabLayout的一种方法
如何获取tabselected@SanikaKadam-pagerAdapter.getPageTitle(tabLayout.getSelectedTabPosition())
使用TabSelected事件
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;
}
}
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);
}