0% found this document useful (0 votes)
13 views3 pages

Source Code MainActivity

The MainActivity.java file implements a login and registration system for an Android application using SQLite for data storage. It includes methods for user login verification and user registration, displaying appropriate messages based on the actions taken. The user interface is built using EditText fields for input and AlertDialog for registration prompts.

Uploaded by

jisin5457
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Source Code MainActivity

The MainActivity.java file implements a login and registration system for an Android application using SQLite for data storage. It includes methods for user login verification and user registration, displaying appropriate messages based on the actions taken. The user interface is built using EditText fields for input and AlertDialog for registration prompts.

Uploaded by

jisin5457
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MainActivity.

java

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends Activity {


private SQLiteDatabase db;
private Cursor dbCursor;
private Modul_DB modulDB;

EditText tUser, tPass, txtUser, txtPass;


Toast t;
Intent i;
[Link] KotakPesan;
private String strUser, strPass;
private String strQuery;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

modulDB = new Modul_DB(this);


db=[Link]();
modulDB.Buat_Tabel_Login(db);

tUser = (EditText) findViewById([Link]);


tPass = (EditText) findViewById([Link]);

public void CekUser (SQLiteDatabase db){


strUser=[Link]().toString();
strPass=[Link]().toString();
String xPass;
if ([Link]().equals("") || [Link]().equals("")){
t= [Link](getApplication(), "User dan Password Harus Diisi",
Toast.LENGTH_SHORT);
[Link]();
[Link]();
}else{
[Link](db);
[Link]();
strQuery="Select nPass From tbl_user Where nUser='" + strUser + "'";
dbCursor=[Link](strQuery, null);
if ([Link]()>0){
[Link]();
xPass = [Link]([Link]("nPass"));
if([Link]().equals(xPass)){
t=[Link](getApplication(), "Login Berhasil",
Toast.LENGTH_SHORT);
[Link]();

Page 1
[Link]

[Link]("");
[Link]("");
i=new Intent([Link],[Link]);
[Link](Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
[Link]();
}else{
t=[Link](getApplication(), "Password Salah",
Toast.LENGTH_SHORT);
[Link]();
}
}else{
t=[Link](getApplication(), "User Belum Terdaftar",
Toast.LENGTH_SHORT);
[Link]();
[Link]("");
[Link]("");
[Link]();
}
}
}

public void Daftar(final SQLiteDatabase db){


//membentuk form daftar
LinearLayout form_daftar = new LinearLayout(this);
form_daftar.setOrientation([Link]);
//inisialisasi objek textview pada form daftar
txtUser=new EditText(this);
form_daftar.addView(txtUser);
[Link]("User");
txtPass=new EditText(this);
form_daftar.addView(txtPass);
[Link]("Password");
//Menampilkan di kotak dialog
KotakPesan=new [Link](this);
[Link]("Form Daftar");
[Link](form_daftar);
[Link]("Simpan", new [Link]() {
@Override

public void onClick(DialogInterface arg0, int arg1) {


// TODO Auto-generated method stub
strUser=[Link]().toString();
strPass=[Link]().toString();
if ([Link]().equals("") || [Link]().equals("")){
t= [Link](getApplication(), "User dan Password Harus
Diisi", Toast.LENGTH_SHORT);
[Link]();
[Link]();
}else{
[Link](db);
[Link]();
ContentValues cvData = new ContentValues();
[Link]("nUser", strUser);
[Link]("nPass", strPass);
[Link]("tbl_user", null, cvData);
try{
t= [Link](getApplication(), "Data Sukses Disimpan",
Toast.LENGTH_SHORT);
[Link]();
[Link]("");
[Link]("");
[Link]();
}catch(Exception e){

Page 2
[Link]

t= [Link](getApplication(), "Data Gagal


Disimpan", Toast.LENGTH_SHORT);
[Link]();
[Link]();
}
}
}
});
[Link]("Batal", new [Link]() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
[Link]();
}
});
[Link]();
}
public void aksi (View ygDiklik){
switch ([Link]()){
case [Link]:
CekUser(db);
break;
case [Link]:
Daftar(db);
break;
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}

Page 3

You might also like