不幸的是,AppName已停止

时间:2016-03-17 22:11:35

标签: android android-fragments textview

我有一个活动和两个片段,xml中的代码: 1 - 活动

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.al_shimaa.my.MainActivity"
android:id="@+id/my_layout"
android:background="@drawable/cairo">
</RelativeLayout>

2-for First Fragment

<?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="wrap_content"
android:background="#929090"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_centerInParent="true">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Login to your wasla account"
    android:id="@+id/title"
    android:layout_gravity="center_horizontal"
    android:textColor="#000000"
    android:clickable="true"
    android:contextClickable="true" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/email"
    android:layout_gravity="center_horizontal"
    android:hint="E-mail"
    android:textColorHint="#000000"
    android:textColor="#000000"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/password"
    android:layout_gravity="center_horizontal"
    android:hint="Password"
    android:textColorHint="#000000"
    android:textColor="#000000"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Login"
    android:id="@+id/loginBtn"
    android:layout_gravity="center_horizontal"
    android:textColor="#ffffff"
    android:background="#b38787" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="i don&apos;t have account , Register Now as"
    android:id="@+id/RegisterTitle"
    android:layout_gravity="center_horizontal"
    android:textColor="#132bc9"
    android:clickable="true"
    android:contextClickable="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Driver"
    android:id="@+id/DriverRegister"
    android:onClick="RegistAsDriver"
    android:textColorLink="@color/colorPrimaryDark"
    android:layout_gravity="center_horizontal"
    android:textColor="#132bc9"
    android:contextClickable="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="User"
    android:id="@+id/userRegister"
    android:onClick="RegistAsUser"
    android:layout_gravity="center_horizontal"
    android:clickable="true" />
   </LinearLayout>

3 - 第二个片段:

 <?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="wrap_content"
android:background="#929090"
android:id="@+id/UserRegisterFragment"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_centerInParent="true">

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/userFname"
    android:layout_gravity="center_horizontal"
    android:hint="First Name"
    android:textColorHint="#000000"
    android:textColor="#000000"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/userLname"
    android:layout_gravity="center_horizontal"
    android:hint="Last Name"
    android:textColorHint="#000000"
    android:textColor="#000000"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/userEmail"
    android:layout_gravity="center_horizontal"
    android:hint="E-mail"
    android:textColorHint="#000000"
    android:textColor="#000000"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:id="@+id/userPass"
    android:layout_gravity="center_horizontal"
    android:hint="Password"
    android:textColorHint="#000000"
    android:textColor="#000000"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/MobileNumber"
    android:layout_gravity="center_horizontal"
    android:hint="Mobile Number"
    android:textColorHint="#000000"
    android:textColor="#000000"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="7dp"
    android:text="Gender"
    android:id="@+id/title"
    android:textColor="#000000" />

<RadioGroup
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textAlignment="center"
    android:layout_gravity="center_horizontal">
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Male"
        android:textColor="#000000"
        android:textAlignment="center"/>
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Female"
        android:textColor="#000000"
        android:textAlignment="center"/>

</RadioGroup>
</LinearLayout>

<Button
    android:layout_width="150dp"
    android:layout_height="match_parent"
    android:gravity="center"
    android:layout_gravity="center_horizontal"
    android:id="@+id/userRegBtn"
    android:text="Register"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Login Now"
    android:id="@+id/LoginFromuser"
    android:onClick="LoginFromUserFrag"
    android:linksClickable="true"
    android:textColorLink="@color/colorPrimaryDark"
    android:layout_gravity="right"
    android:textColor="#132bc9"
    android:clickable="true" />
 </LinearLayout>

4-主要活动

public class MainActivity extends Activity {
FragmentManager manager;
TextView userRegist;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Login_Fragment login = new Login_Fragment();
    manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.add(R.id.my_layout, login, "LoginFragment");
    transaction.commit();
} public void RegistAsUser(){
   User_RegisterFragment user = new User_RegisterFragment();
   manager = getFragmentManager();
   FragmentTransaction transaction = manager.beginTransaction();
   transaction.add(R.id.my_layout, user, "UserRegisterFrag");
   transaction.addToBackStack(null);
   transaction.commit();
}

然后,当我按下textView(用户)时,应用终止并显示此消息:不幸的是(我的应用名称)已停止

0 个答案:

没有答案