D
dnd24
Neues Mitglied
- 0
Hallo,
das ist mein erster Beitrag hier und ich habe ein Problem.
Ich möchte ganz primitiv einen Login machen, der mich auf eine zweite Activity bringt.
Bei mir klappt das aber nicht. Ich wäre euch dankbar wenn ihr mir helfen könntet.
Kann sein, dass es ein "Leichtsinnsfehler" ist, solange programmiere ich noch noch nicht in AS.
Login.java
package dnd24.loginapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends AppCompatActivity {
private static EditText username;
private static EditText password;
private static Button login_button;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
LoginButton();
}
public void LoginButton(){
username = (EditText)findViewById(R.id.editText_user);
password = (EditText)findViewById(R.id.editText_password);
login_button = (Button)findViewById(R.id.button_login);
login_button.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
if (username.getText().toString().equals("Name")){
if (password.getText().toString().equals("Passwort")){
Intent intent = new Intent("dnd24.loginapp.User");
startActivity(intent);
}
} else {
Toast.makeText(Login.this,"Du hast dich vertippt ",
Toast.LENGTH_SHORT).show();
}
}
}
);
}
}
User.java
package dnd24.loginapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class User extends AppCompatActivity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
}
}
activity_user.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="dnd24.loginapp.User">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to the second page" />
</android.support.constraint.ConstraintLayout>
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dnd24.loginapp.Login">
<RelativeLayout
android:layout_width="138dp"
android:layout_height="503dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TextView
android:id="@+id/textView_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView_login"
android:layout_marginTop="132dp"
android:text="Username" />
<TextView
android:id="@+id/textView_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Page" />
<TextView
android:id="@+id/textView_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView_username"
android:layout_marginTop="25dp"
android:text="Password" />
<Button
android:id="@+id/button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Login" />
</RelativeLayout>
<RelativeLayout
android:layout_width="222dp"
android:layout_height="530dp"
tools:layout_editor_absoluteX="146dp"
tools:layout_editor_absoluteY="-1dp">
<EditText
android:id="@+id/editText_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="134dp"
android:ems="10"
android:inputType="textPersonName" />
<EditText
android:id="@+id/editText_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText_user"
android:ems="10"
android:inputType="textPersonName" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dnd24.loginapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@Style/AppTheme">
<activity android:name="dnd24.loginapp.Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="dnd24.loginapp.User"></activity>
</application>
</manifest>
das ist mein erster Beitrag hier und ich habe ein Problem.
Ich möchte ganz primitiv einen Login machen, der mich auf eine zweite Activity bringt.
Bei mir klappt das aber nicht. Ich wäre euch dankbar wenn ihr mir helfen könntet.
Kann sein, dass es ein "Leichtsinnsfehler" ist, solange programmiere ich noch noch nicht in AS.
Login.java
package dnd24.loginapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends AppCompatActivity {
private static EditText username;
private static EditText password;
private static Button login_button;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
LoginButton();
}
public void LoginButton(){
username = (EditText)findViewById(R.id.editText_user);
password = (EditText)findViewById(R.id.editText_password);
login_button = (Button)findViewById(R.id.button_login);
login_button.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
if (username.getText().toString().equals("Name")){
if (password.getText().toString().equals("Passwort")){
Intent intent = new Intent("dnd24.loginapp.User");
startActivity(intent);
}
} else {
Toast.makeText(Login.this,"Du hast dich vertippt ",
Toast.LENGTH_SHORT).show();
}
}
}
);
}
}
User.java
package dnd24.loginapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class User extends AppCompatActivity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
}
}
activity_user.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="dnd24.loginapp.User">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to the second page" />
</android.support.constraint.ConstraintLayout>
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dnd24.loginapp.Login">
<RelativeLayout
android:layout_width="138dp"
android:layout_height="503dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TextView
android:id="@+id/textView_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView_login"
android:layout_marginTop="132dp"
android:text="Username" />
<TextView
android:id="@+id/textView_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Page" />
<TextView
android:id="@+id/textView_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView_username"
android:layout_marginTop="25dp"
android:text="Password" />
<Button
android:id="@+id/button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Login" />
</RelativeLayout>
<RelativeLayout
android:layout_width="222dp"
android:layout_height="530dp"
tools:layout_editor_absoluteX="146dp"
tools:layout_editor_absoluteY="-1dp">
<EditText
android:id="@+id/editText_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="134dp"
android:ems="10"
android:inputType="textPersonName" />
<EditText
android:id="@+id/editText_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText_user"
android:ems="10"
android:inputType="textPersonName" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dnd24.loginapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@Style/AppTheme">
<activity android:name="dnd24.loginapp.Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="dnd24.loginapp.User"></activity>
</application>
</manifest>