Android Programming -7 java programming

Hi guys in this tutorial we will continue the java programming.

In my previous tutorial, I started the java programming. If you have not read it yet, I recommend you read it first.

Today, we will take a string that the user writes in edittext, check it and perform different scenarios according to the result.

package com.example.mac.makale;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
EditText kullanici_adi,sifre;
Button login;
TextView mesaj;
    protected void onCreate(Bundle savedInstanceState) {
        login.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (kullanici_adi.getText()=="kubrahebes" && sifre.getText()=="12345") {
                    mesaj.setText("Başarılı giriş");
                else {
                    mesaj.setText("Başarısız Giriş !!!");

If we examine our example;

We define edittext, textview and button globally  variables. Then we assign the components we define in xml codes to our variables with findviewbyid function. By setting the onclick feature of the Login button, we encode the actions to be performed even when the button is clicked.

With the gettext feature of Edittext, we take and check the user name and password values ​​entered by the user.  We define manually User name ‘kubrahebes’, password ‘12345′.  And by comparing the values entered by the user with these values.

We inform the user by typing whether the login is successful or not. We provide this information through the textview settext function.

About Kübra Hebeş

Bilgisayar Mühendisi

Leave a Reply

Your email address will not be published. Required fields are marked *