я разрабатываю 2 XML деятельность (Логин, регистрация) и я хочу 2 кнопки для обмена фрагментов с двумя XML деятельностиAndroid фрагмент не заменит
это мой код он не получил какую-либо ошибку, но ничего не случится
Button btn1,btn2;
Fragment loginfrag,signupfrag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.login_button);
btn2 = (Button) findViewById(R.id.signup_button);
loginfrag = new loginfr();
signupfrag = new signupfr();
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
}
@Override
public void onClick(View view) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
if (view == btn1)
{
ft.replace(R.id.fragment_screen,loginfrag);
ft.commit();
Toast.makeText(this,"login",Toast.LENGTH_LONG);
}
else if (view == btn2){
ft.replace(R.id.fragment_screen,signupfrag);
ft.commit();
Toast.makeText(this,"signup",Toast.LENGTH_LONG);
}
}
и это Войти деятельность
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="24dp"
android:weightSum="1">
<!-- Email Label -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Email"
android:hint="Eamil"/>
<!-- Password Label -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:hint="password"/>
<Button
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_gravity="center"
android:textAlignment="center"
android:text="تسجيل الدخول"/>
<TextView android:id="@+id/link_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="ليس لديك حساب؟سجل الآن"
android:textColor="#f000"
android:gravity="center"
android:textSize="16dip"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
регистрацию активности
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="56dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:weightSum="1">
<!-- Email Label -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Email_signup"
android:hint="Eamil"/>
<!-- Password Label -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/password_signup"
android:hint="password"/>
<Button
android:id="@+id/btn_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_gravity="center"
android:textAlignment="center"
android:text="تسجيل عضوية جديدة "/>
<TextView android:id="@+id/link_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text=" لديك حساب؟قم بتسجيل الدخول"
android:textColor="#f000"
android:gravity="center"
android:textSize="16dip"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
в основной деятельности это XML-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttons_container"
android:layout_below="@id/line0">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/signup_button"
android:layout_weight="1"
android:text="التسجيل"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/login_button"
android:layout_weight="1"
android:text="تسجيل الدخول" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_below="@id/buttons_container"
android:id="@+id/relativeLayout">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.amr.testapp.loginfr"
tools:layout="@layout/login"
android:id="@+id/fragment_screen"
android:layout_below="@id/buttons_container" />
</RelativeLayout>
является тост сообщение отображается? – rafsanahmad007
no ,,, не показывал –