Rekan rekan sekalaian kalai ini skripsilive membagi bagaimana caranya mengkoneksikan login dengan databse mysql.
Langkah pertama buat projek di android

gambar desain seperti diatas

atau file xmlnya dengan coding di bawah ini :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bgapot"
    android:orientation="vertical"
    android:padding="10sp" >

    <EditText
        android:id="@+id/txt_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="username"
        android:singleLine="true"
        android:textColorHint="#000000" >

        <requestFocus />
    </EditText>

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

    </EditText>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btn_login"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="Login" />

        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="Batal" />

    </RelativeLayout>

</LinearLayout>


UNTUK JAVANYA 

package com.example.login;


import driver.Utils;
import driver.XMLParser;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    String nama,pass;
    String otentikasi="";
    EditText edNama,edPass;
    XMLParser parser = new XMLParser();
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        edNama=(EditText)findViewById(R.id.txt_name);
        edPass=(EditText)findViewById(R.id.password);
           
        Button  btnBatal=(Button)findViewById(R.id.btn_cancel);
        btnBatal.setOnClickListener(new View.OnClickListener() {
                public void onClick(View arg0) {
                    //Intent  i= new Intent(MainActivity.this,MainActivity.class);
                     //startActivity(i);
                     finish();
        }});
        
        Button  btnLogin=(Button)findViewById(R.id.btn_login);
        btnLogin.setOnClickListener(new View.OnClickListener() {
                public void onClick(View arg0) {
                
                      nama=edNama.getText().toString();
                      pass=edPass.getText().toString();
                                      
                     if(nama.equalsIgnoreCase("")){
                         isiNama();
                     }
                     else if(pass.equalsIgnoreCase("")){
                         isiPass();
                     }

                     else{
                             Utils ip=new Utils();
                             String myip=ip.getIP();
                             nama=nama.replaceAll(" ", "_");
                             pass=pass.replaceAll(" ", "_");
                             String URL = myip+"android/login.php?username="+nama+"&password="+pass+"&ket=ok";
                             String xml =parser.getXmlFromUrl(URL);

                             if(xml.indexOf("sukses")>=0){
                             Intent i = new Intent(MainActivity.this, Menu.class); 
                               i.putExtra("xml", xml);
                               startActivity(i);  
                              //finish();
                         }
                         else{
                             salah();
                         }
                     }}});  
        }
      //-------------------------------------------------------------------------------------------  
            public void isiNama(){
                new AlertDialog.Builder(this)
                .setTitle("Silakan Isi Nama")
                .setMessage("Maaf, Silakan isi Nama Anda terlebih dahulu....")
                .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dlg, int sumthin) {
                    }})
                .show();
            }
            
            public void pesan(String ps){
                new AlertDialog.Builder(this)
                .setTitle("Pesan")
                .setMessage(ps)
                .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dlg, int sumthin) {
                    }})
                .show();
            }
    //-------------------------------------------------------------------------------------------        
            public void isiPass(){
                new AlertDialog.Builder(this)
                .setTitle("Silakan Isi Pass")
                .setMessage("Maaf, Silakan isi Pass Anda terlebih dahulu....")
                .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dlg, int sumthin) {
                    }})
                .show();
            }
            
            public void isiKodeCustomer(){
                new AlertDialog.Builder(this)
                .setTitle("Silakan Isi Kode Customer")
                .setMessage("Maaf, Silakan isi Kode Customer terlebih dahulu....")
                .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dlg, int sumthin) {
                    }})
                .show();
            }
    //-------------------------------------------------------------------------------------------         
            public void salah(){
                new AlertDialog.Builder(this)
                .setTitle("ontentikasi salah")
                .setMessage("Maaf, username "+nama+" dan pass "+pass+" SALAH ! cek kembali dengan benar....")
                .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dlg, int sumthin) {
                    }})
                .show();
            }
       
    //-------------------------------------------------------------------------------------------
        
           
   
}

jasa pembuatan program skripsi dan tugas akhir

× Konsultasi Sekarang