elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  ayuda con checkbox para recordar datos en android
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ayuda con checkbox para recordar datos en android  (Leído 1,710 veces)
General Dmitry Vergadoski


Desconectado Desconectado

Mensajes: 881


General de División.


Ver Perfil
ayuda con checkbox para recordar datos en android
« en: 27 Agosto 2015, 20:42 pm »

hola amigos quiero hacer un checkbox que me permita recordar el usuario y la contraseña de mi login en android pero ya he intentado todo y no puedo hacerlo, el checkbox cuando este activo debera recordar los datos y cuando este inactivo dejara de recordarlos, aqui les dejo mi codigo:


login.xml

Código
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:orientation="vertical" >
  6.  
  7.    <EditText
  8.        android:id="@+id/editTextUserNameToLogin"
  9.        android:layout_width="match_parent"
  10.        android:layout_height="wrap_content"
  11.        android:ems="10"
  12.        android:hint="Usuario" >
  13.  
  14.        <requestFocus />
  15.    </EditText>
  16.  
  17.    <EditText
  18.        android:id="@+id/editTextPasswordToLogin"
  19.        android:layout_width="match_parent"
  20.        android:layout_height="wrap_content"
  21.        android:ems="10"
  22.        android:hint="Clave"
  23.        android:inputType="textPassword" />
  24.  
  25.    <CheckBox
  26.        android:id="@+id/checkBox1"
  27.        android:layout_width="wrap_content"
  28.        android:layout_height="wrap_content"
  29.        android:text="Recordar Datos" />
  30.  
  31.    <Button
  32.        android:id="@+id/buttonSignIn"
  33.        android:layout_width="fill_parent"
  34.        android:layout_height="wrap_content"
  35.        android:text="Aceptar" />
  36.  
  37. </LinearLayout>

HomeActivity.java

Código
  1. package com.techblogon.loginexample;
  2.  
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. public class HomeActivity extends Activity
  14. {
  15. Button btnSignIn,btnSignUp;
  16. LoginDataBaseAdapter loginDataBaseAdapter;
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState)
  20. {
  21.     super.onCreate(savedInstanceState);
  22.     setContentView(R.layout.main);
  23. Button close_Button = (Button) findViewById(R.id.close_Button);
  24.    close_Button.setOnClickListener(new OnClickListener() {
  25.  
  26.        @Override
  27.        public void onClick(View v) {
  28.         finish();
  29.        }
  30.    });
  31.  
  32.  
  33.  
  34.     // create a instance of SQLite Database
  35.     loginDataBaseAdapter=new LoginDataBaseAdapter(this);
  36.     loginDataBaseAdapter=loginDataBaseAdapter.open();
  37.  
  38.     // Get The Refference Of Buttons
  39.     btnSignIn=(Button)findViewById(R.id.buttonSignIN);
  40.     btnSignUp=(Button)findViewById(R.id.buttonSignUP);
  41.  
  42.    // Set OnClick Listener on SignUp button
  43.    btnSignUp.setOnClickListener(new View.OnClickListener() {
  44. public void onClick(View v) {
  45. // TODO Auto-generated method stub
  46.  
  47. /// Create Intent for SignUpActivity  and Start The Activity
  48. Intent intentSignUP=new Intent(getApplicationContext(),SignUPActivity.class);
  49. startActivity(intentSignUP);
  50. }
  51. });
  52. }
  53. // Methos to handleClick Event of Sign In Button
  54. public void signIn(View V)
  55.   {
  56. final Dialog dialog = new Dialog(HomeActivity.this);
  57. dialog.setContentView(R.layout.login);
  58.    dialog.setTitle("Ingresar");
  59.  
  60.    // get the Refferences of views
  61.    final  EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);
  62.    final  EditText editTextPassword=(EditText)dialog.findViewById(R.id.editTextPasswordToLogin);
  63.  
  64. Button btnSignIn=(Button)dialog.findViewById(R.id.buttonSignIn);
  65.  
  66. // Set On ClickListener
  67. btnSignIn.setOnClickListener(new View.OnClickListener() {
  68.  
  69. public void onClick(View v) {
  70. // get The User name and Password
  71. String userName=editTextUserName.getText().toString();
  72. String password=editTextPassword.getText().toString();
  73.  
  74. // fetch the Password form database for respective user name
  75. String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);
  76.  
  77. // check if the Stored password matches with  Password entered by user
  78. if(password.equals(storedPassword))
  79. {
  80. Toast.makeText(HomeActivity.this, "Ingreso Satifactorio", Toast.LENGTH_LONG).show();
  81. dialog.dismiss();
  82. }
  83. else
  84. {
  85. Toast.makeText(HomeActivity.this, "Usuario O Clave Erronea", Toast.LENGTH_LONG).show();
  86. }
  87. }
  88. });
  89.  
  90.  
  91.  
  92. dialog.show();
  93.  
  94. }
  95.  
  96.  
  97. @Override
  98. protected void onDestroy() {
  99. super.onDestroy();
  100.    // Close The Database
  101. loginDataBaseAdapter.close();
  102.  
  103.  
  104. }
  105. }
  106.  

muchas gracias de antemano.


« Última modificación: 28 Agosto 2015, 16:59 pm por doctorman » En línea

Primero mártir que arrodillado frente una dictadura.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Actualizar checkbox base de datos (PHP + MySQL)
PHP
KateLibby 1 15,175 Último mensaje 15 Abril 2010, 23:13 pm
por KateLibby
Problema con checkbox y base de datos
PHP
betocube 5 5,911 Último mensaje 21 Abril 2011, 22:33 pm
por betocube
Una ayuda para recordar los checkboxes seleccionados
.NET (C#, VB.NET, ASP)
Eleкtro 2 2,064 Último mensaje 6 Enero 2013, 17:47 pm
por ABDERRAMAH
Capturar datos de checkbox
Programación Visual Basic
rvilla777 1 1,884 Último mensaje 8 Septiembre 2013, 16:10 pm
por noele1995
Cómo activar la itinerancia de datos en iOS y Android para el fin del roaming
Noticias
wolfbcn 0 1,621 Último mensaje 9 Junio 2017, 01:41 am
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines