How do I get the data from the person who just logged in to my system?

Asked

Viewed 75 times

1

the previous question I wanted to know the validation and I already realized it , now I want to know how I took the data of the person who logged in and play to another screen and separate each data of the person for example name ai plays in a textview professional ai play in another textview ...

I’m trying a lot of different ways but none of them worked ?

package com.example.scrumfacil;

import android.app.Activity;
import android.content.Intent;
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 MainActivity extends Activity {


    private Button cadastro; 
    private Button login;
    private EditText logar;
    private EditText senha;
     Intent it;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        login = (Button)findViewById(R.id.btnLogin);

        login.setOnClickListener(new View.OnClickListener() {





            @Override
            public void onClick(View arg0) {
                // como colocar o usuario e senha no lugar do null

                logar =(EditText)findViewById(R.id.login);
                String logarr=logar.getText().toString();
                senha=(EditText)findViewById(R.id.senha);
                String senhaa=senha.getText().toString();


                CriaBanco validar = new CriaBanco( MainActivity.this, MainActivity.this);

                validar.validar(logarr,senhaa);

            }
        });     



        cadastro = (Button)findViewById(R.id.btnCadastrar);

        cadastro.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(new Intent( MainActivity.this,CadastroActivity.class));

            }
        });





    }


}

    package com.example.scrumfacil;



import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class CadastroActivity extends Activity {

    private Button comfirmar; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cadastro);     



        comfirmar = (Button)findViewById(R.id.btnComfirmarCadastro);

        comfirmar.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {


                EditText edtN=(EditText)findViewById(R.id.editNome);
                String nome1 =edtN.getText().toString();

                EditText edtU=(EditText)findViewById(R.id.editUsuario);
                String usuario =edtU.getText().toString();

                EditText edts=(EditText)findViewById(R.id.editSenha);
                String senha =edts.getText().toString();

                EditText edtc=(EditText)findViewById(R.id.editCpf);
                String cpf =edtc.getText().toString();

                EditText edtp=(EditText)findViewById(R.id.editProf);
                String profissao =edtp.getText().toString();

                EditText edtn=(EditText)findViewById(R.id.editNasc);
                String nascimento =edtn.getText().toString(); 

                if(edtN.getText().toString().trim().equals("")){
                       edtN.setError("Campo nome vazio");


                }else if (edtU.getText().toString().trim().equals("")){

                    edtU.setError("Campo usuario vazio");

                }           
                else if (edts.getText().toString().trim().equals("")){

                    edts.setError("Campo senha vazio");

                }           
                else if (edtc.getText().toString().trim().equals("")){

                    edtc.setError("Campo CPF vazio");

                }           
                else if (edtp.getText().toString().trim().equals("")){
                    edtp.setError("Campo profissao vazio");

                }           
                else if (edtn.getText().toString().trim().equals("")){

                    edtn.setError("Campo nascimento vazio");

                }else{

                CriaBanco cb = new CriaBanco(CadastroActivity.this,CadastroActivity.this);
                cb.salvar(nome1, usuario, senha, cpf, profissao, nascimento);     


                startActivity(new Intent(CadastroActivity.this,MainActivity.class));


                    }
            }
        });



    }

}

package com.example.scrumfacil;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender.OnFinished;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class CriaBanco extends SQLiteOpenHelper {
    private static final String NOME_BANCO = "banco.db";
    private static final int VERSAO = 1;
    private Context context;
    private SQLiteDatabase db;
     private Activity activity;
    public CriaBanco(Context context,Activity activity) {

        super(context, NOME_BANCO, null, VERSAO);
        this.context = context;
        this.activity=  activity;   
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        try{
        String sql = "create table if not exists CadastroUsuario("
                + "usuario varchar(20) primary key not null,"
                + "nome varchar(80)not null," + "senha varchar (15) not null ,"
                + "cpf integer (11)not null ,"
                + "Profissao varchar(35) not null,"
                + " nascimento date not null)";
        db.execSQL(sql);
        }catch(Exception ex){
            Toast.makeText(context,"Error ao criar banco",Toast.LENGTH_LONG).show();
        }
        }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public void salvar(String nome1, String usuario, String senha, String cpf,
            String profissao, String nascimento) {

        try{

        String sql = "insert into CadastroUsuario(nome,usuario,senha,cpf,profissao,nascimento) values ('"
                + nome1
                + "','"
                + usuario
                + "','"
                + senha
                + "','"
                + cpf
                + "','"
                + profissao + "','" + nascimento + "')";
        getWritableDatabase().execSQL(sql);
        }catch(Exception ex){
            ex.getMessage();
        Toast.makeText(context,ex.getMessage(),Toast.LENGTH_LONG).show();
        }

    }

    public void validar(String usuario, String senha) {
        try{
        String sql = "select usuario,senha from CadastroUsuario where usuario ='"
                + usuario + "' and senha ='" + senha + "' ";

        Cursor c = getReadableDatabase().rawQuery(sql, null);

        if ( c.getCount()==1){

            Toast.makeText(context, "Login efetuado com sucesso",Toast.LENGTH_LONG).show();

        Intent i = new Intent(activity,PlanejamentoActivity.class); 
        activity.startActivity(i);


        }else{
            Toast.makeText(context, "Usuario ou senha incorreta", Toast.LENGTH_LONG).show();        


        }
        }catch(Exception ex){
            ex.getMessage();
        Toast.makeText(context,ex.getMessage(),Toast.LENGTH_LONG).show();
        }finally{

        }




    }





    }
  • The select you are using to validate the usario and senha can bring the rest of the data you want. You only need to change the select

  • I made some modifications but it’s returning null and when I take the ""+ , there is nothing

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.