-1

这是我在应用程序数据库中插入行的方法。但它只插入一行。所以我必须在数据库中添加多行。此代码用于我的应用程序中的新用户注册。

提前致谢.....

public void addProductToCart(String username, String password,
        String email, String contact, String bloodgroup, String city, String state) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(colUsername, username);
    contentValues.put(colPassword, password);
    contentValues.put(colEmail, email);
    contentValues.put(colContact, contact);
    contentValues.put(colBloodgroup, bloodgroup);
    contentValues.put(colCity, city);
    contentValues.put(colState, state);
    db.insert(USERTABLE, colUsername, contentValues);
    db.close();

    context.runOnUiThread(new Runnable() {

        public void run() {
            Toast.makeText(context, "You have registered successfully.",
                    Toast.LENGTH_LONG).show();
            context.finish();
        }
    });
}
4

2 回答 2

1

I don't think there is something else that android supports, but my solution will be to build for that a new class with the Fields you need, and then pass as parameter to the addProductToCart method a list of all the objects you want to put. Inside the method do for loop until you get to the end of the list.

于 2012-04-05T13:34:30.543 回答
0

一次注册多个用户是不可能的,如果您想一次添加更多用户,请使用数据库类中的后端进程。尝试在代码中添加值,而不是使用用户界面。如果您将单击功能设置为按钮,则使用您喜欢的值多次调用该方法。

像这样,

db.addProductToCart(username1,password1,email1,contact1,bloodgroup1,city1,state1); db.addProductToCart(username2,password2,email2,contact2,bloodgroup2,city2,state2); db.addProductToCart(username3,password3,email3,contact3,bloodgroup3,city3,state3);

于 2012-04-06T05:05:05.887 回答