Simple Login



Kali ini saya akan mendemokan simple login dengan android, langkah awal yang harus di buat adalah buat project baru, bebas namanya (selanjutnya saya yakin anda sudah bias :D )
Ok,setelah project terbentuk, yang kita lakukan adalah membuat view, namanya  adalah activity_loe_gin.xml, ini kodenya :
activity_loe_gin.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Loe_gin" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignParentTop="true"
        android:layout_marginTop="28dp"
        android:ems="10"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:text="Nama Loeee"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="15dp"
        android:text="Password Loeeee"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="48dp"
        android:text="Loe_gin" />

</RelativeLayout>


Jika sudah, lalu file controlnya , yaitu  Loe_gin.java ini codenya :

Loe_gin.java

package com.example.experimen2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.*;

public class Loe_gin extends Activity {
EditText nama,pass;
Button ok;
@Override
       protected void onCreate(Bundle savedInstanceState)
       {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_loe_gin);
           nama=(EditText)findViewById(R.id.editText1);
           pass=(EditText)findViewById(R.id.editText2);
           ok=(Button)findViewById(R.id.button1);
           ok.setOnClickListener(login);
       }

View.OnClickListener login = new View.OnClickListener()
{
       @Override
       public void onClick(View arg0)
       {
       if(nama.getText().toString().equals("matt")&& pass.getText().toString().equals("matt"))
       {
              Toast.makeText(getBaseContext()," selamat anda benarrrr 100 buat anda",Toast.LENGTH_SHORT).show();
       }
       else
       {
              Toast.makeText(getBaseContext()," maaf anda sangat sangat kurang bejo, maaf",Toast.LENGTH_SHORT).show();
       }
       }
};
      
}



Setelah semua  di atas beres , tinggal RUN !!!!!! untuk download projectnya bisa klik di siniiiiiiiiiiii

Komentar

Postingan Populer