Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- EditText username;
- EditText password;
- Button loginbutton;
- DataModel data;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- data = new DataModel();
- data.setUsername("Don");
- data.setPassword("Bradman");
- username = (EditText) findViewById(R.id.editusername);
- password = (EditText) findViewById(R.id.editpassword);
- loginbutton = (Button) findViewById(R.id.loginbutton);
- loginbutton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // Perform action on click
- if (username.getText().toString().equals("Prashant") && password.getText().toString().equals("Joshi")){
- Toast.makeText(MainActivity.this, "You have successfully logged in", Toast.LENGTH_SHORT).show();
- }
- else {
- Toast.makeText(MainActivity.this, "Wrong Username or Password", Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- }
- public class DataModel {
- String username;
- String password;
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- }
- <LinearLayout 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:orientation="vertical"
- android:paddingBottom="10dp"
- android:paddingLeft="10dp"
- android:paddingRight="10dp"
- android:paddingTop="10dp"
- >
- <EditText
- android:id="@+id/editusername"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Username"
- android:inputType="textNoSuggestions"/>
- <EditText
- android:id="@+id/editpassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Password"
- android:inputType="textPassword"/>
- <Button
- android:id="@+id/loginbutton"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:onClick="onLoginClicked"
- android:text="Login Button"/>
- </LinearLayout>
Add Comment
Please, Sign In to add comment