Android的!在新的活动中获取数据库行 [英] Android!! Fetch database row in new activiy

查看:89
本文介绍了Android的!在新的活动中获取数据库行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户可以注册的sqlite数据库!我已成功创建登录表单,当登录成功(用户名和密码与数据库匹配)时,用户将被重定向到另一个活动。我想要的是在用户被重定向的活动中,

显示他的整个数据库行(id,用户名,书籍,电子邮件,课程,密码,学生姓名)!有任何想法吗??如果你能帮助我,我将非常感激,因为这是完成我的最后一年项目的最后任务。我使用Android Studio!我创建了像Adapters数据库助手和光标这样的人员这很紧急! !!



这是我的数据库创建代码:



I have a sqlite database that the user can register to! I have successfully created a login form and when the login is successful (username & password match the database's) the user is redirected to another activity. What i want is in the activity that the user is redirected,
to display his entire database row (id,username, books,email,course, password, student name)!! Any ideas?? I would really appreciate if you could help me as this is the final task to complete my final year project..I use Android Studio!! I have created staff like Adapters database helpers ans cursorsThis is urgent!!!

Here is my database creation code:

static final String DATABASE_CREATE = "create table "+"LOGIN"+
        "( " +"ID"+" integer primary key autoincrement,"+ "USERNAME  varchar2," +
        "PASSWORD varchar2, COURSE varchar2, EMAIL varchar2, STUDENT_NAME varchar2); ";





这里我是如何在数据库中存储数据的:





Here is how I store data in the database:

public void insertEntry(String userName,String password,String course,String email, String student_name)
{
    ContentValues newValues = new ContentValues();
    // Assign values for each row.
    newValues.put("USERNAME", userName);
    newValues.put("PASSWORD",password);
    newValues.put("COURSE", course);
    newValues.put("EMAIL",email);
    newValues.put("STUDENT_NAME", student_name);
 
    // Insert the row into your table
    db.insert("LOGIN", null, newValues);
    ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
}





最后这里是启动新活动代码的登录信息:



And finally here is the login that starts the new activity code:

if(password.equals(storedPassword))
            {
                Toast.makeText(MyActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
                dialog.dismiss();
                startActivity(new Intent(MyActivity.this, Login_home.class));
            }
            else
            {
                Toast.makeText(MyActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
            }

推荐答案

浏览以下代码片段:

1.在LoginActivity:

A walk through of the following code snippets:
1. in the LoginActivity:
// create a bundle object to store user's data
Bundle bundle = new Bundle();
// assign the values as key-value pairs
bundle.putString("username", username);
bundle.putString("email", email);
      
// create the intent
Intent i = new Intent(LoginActivity.this, NewActivity.class);
// assign the bundle to the intent
i.putExtras(bundle);
// finally start the new activity
startActivity(i);



2.在NewActivity中


2. in the NewActivity

//create a bundle object to store the extras
Bundle bundle=getIntent().getExtras();
//get the values by their keys
String username=bundle.getString("username");
String email=bundle.getString("email");
// do whatever you like to the data


这篇关于Android的!在新的活动中获取数据库行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆