Alguien me puede ayudar, los campos para iniciar sesión son :
correo y contraseña.
El archivo base de datos:
Cita:
El archivo de inicio sesión (login.java):package com.cine.cinepapaya;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.Vector;
public class BDCinePapayaSQLite extends SQLiteOpenHelper {
private static final String DATABASE_NAME="CinePapaya.sqlite";
public static final String CORREO="correo";
public static final String PASSWORD="password";
public static final String NOMBRE="nombre";
public static final String DNI="dni";
public BDCinePapayaSQLite(Context context)
{
super(context,DATABASE_NAME,null,1);
}
/** Called when the activity is first created. */
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE Usuarios(id INTEGER PRIMARY KEY AUTOINCREMENT, correo TEXT UNIQUE NOT NULL, password TEXT NOT NULL, nombre TEXT NOT NULL, dni INTEGER NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
android.util.Log.v("Constante", "Actualiza la base de datos y destruye la base de datos antigua con el mismo nombre");
db.execSQL("DROP table if exists Usuarios");
onCreate(db);
}
}
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.Vector;
public class BDCinePapayaSQLite extends SQLiteOpenHelper {
private static final String DATABASE_NAME="CinePapaya.sqlite";
public static final String CORREO="correo";
public static final String PASSWORD="password";
public static final String NOMBRE="nombre";
public static final String DNI="dni";
public BDCinePapayaSQLite(Context context)
{
super(context,DATABASE_NAME,null,1);
}
/** Called when the activity is first created. */
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE Usuarios(id INTEGER PRIMARY KEY AUTOINCREMENT, correo TEXT UNIQUE NOT NULL, password TEXT NOT NULL, nombre TEXT NOT NULL, dni INTEGER NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
android.util.Log.v("Constante", "Actualiza la base de datos y destruye la base de datos antigua con el mismo nombre");
db.execSQL("DROP table if exists Usuarios");
onCreate(db);
}
}
Cita:
Layout de login.java (login.xml)package com.cine.cinepapaya;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button ingresar = (Button) findViewById(R.id.ingresar);
ingresar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
String correo = ((EditText) findViewById(R.id.editcorreo)).getText().toString( );
String password = ((EditText) findViewById(R.id.editpassword)).getText().toStrin g();
if(correo.equals("[email protected]") && password.equals("123456"))
{
Intent ingreso = new Intent(Login.this, Bienvenida.class);
startActivity(ingreso);
Toast.makeText(getApplicationContext(),"Iniciando Sesión", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(),"Correo o Contraseña Inconrrecto", Toast.LENGTH_SHORT).show();
}
}
});}
public void registrar1(View b)
{
Intent it=new Intent(this,Registrar.class);
startActivity(it);
}
}
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button ingresar = (Button) findViewById(R.id.ingresar);
ingresar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
String correo = ((EditText) findViewById(R.id.editcorreo)).getText().toString( );
String password = ((EditText) findViewById(R.id.editpassword)).getText().toStrin g();
if(correo.equals("[email protected]") && password.equals("123456"))
{
Intent ingreso = new Intent(Login.this, Bienvenida.class);
startActivity(ingreso);
Toast.makeText(getApplicationContext(),"Iniciando Sesión", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(),"Correo o Contraseña Inconrrecto", Toast.LENGTH_SHORT).show();
}
}
});}
public void registrar1(View b)
{
Intent it=new Intent(this,Registrar.class);
startActivity(it);
}
}
Cita:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="118dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/logo"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:alwaysDrawnWithCache="false" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="15dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="@+id/txtcorreo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Correo"
android:textColor="#FB9900"
android:textSize="20dp"
android:textStyle="bold" />
<EditText
android:id="@+id/editcorreo"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#fff"
android:inputType="textEmailAddress">
</EditText>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="10dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="@+id/txtpassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Contraseña"
android:textColor="#FB9900"
android:textSize="20dp"
android:textStyle="bold" />
<EditText
android:id="@+id/editpassword"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#fff"
android:inputType="textEmailAddress"
android:password="true">
</EditText>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="15dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="@+id/ingresar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ingresar" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="No tienes cuenta? Regístrate :3"
android:textColor="#FB9900"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/registrar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Registrar"
android:onClick="registrar1"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
</TableLayout>
</LinearLayout>
</ScrollView>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="118dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/logo"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:alwaysDrawnWithCache="false" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="15dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="@+id/txtcorreo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Correo"
android:textColor="#FB9900"
android:textSize="20dp"
android:textStyle="bold" />
<EditText
android:id="@+id/editcorreo"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#fff"
android:inputType="textEmailAddress">
</EditText>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="10dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="@+id/txtpassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Contraseña"
android:textColor="#FB9900"
android:textSize="20dp"
android:textStyle="bold" />
<EditText
android:id="@+id/editpassword"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#fff"
android:inputType="textEmailAddress"
android:password="true">
</EditText>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="15dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="@+id/ingresar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ingresar" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="No tienes cuenta? Regístrate :3"
android:textColor="#FB9900"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/registrar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Registrar"
android:onClick="registrar1"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
</TableLayout>
</LinearLayout>
</ScrollView>