Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:05:33+00:00 2026-06-10T10:05:33+00:00

I want my Onclick method that is used used to insert data into a

  • 0

I want my Onclick method that is used used to insert data into a database to first check if data exist. If there is data, a toast message appears. how can I accomplish this. My OnClick is below. I just it to verify there is a username and password. If there is, the user receives a toast.

 @Override
public void onClick (View v) {

    rUsername = rName.getText().toString();
    rPasscode = rCode.getText().toString();

    RegDetails regDetails = new RegDetails();
    regDetails.setrName(bundleRegName);
    regDetails.setpCode(bundleRegCode);
    if(v.getId()==R.id.rtn_button){
        finish();

    }else if(v.getId()==R.id.reg_button){
        insertCredentials(regDetails);
    }
}
    private void insertCredentials(RegDetails regDetails){

        LoginDB androidOpenDBHelper = new LoginDB(this);
        SQLiteDatabase sqliteDB = androidOpenDBHelper.getWritableDatabase();

        ContentValues contentValues = new ContentValues();
        contentValues.put(LoginDB.COLUMN_NAME_USERNAME, rUsername);
        contentValues.put(LoginDB.COLUMN_NAME_PASSWORD, rPasscode);

        long affectedColumnid = sqliteDB.insert(LoginDB.TABLE_NAME_CREDENTIALS, null, contentValues);

        Toast.makeText(getApplicationContext(), "Credentials Saved! Please login" + affectedColumnid, Toast.LENGTH_SHORT).show();
        sqliteDB.close();
        finish();
    }   

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:05:35+00:00Added an answer on June 10, 2026 at 10:05 am

    The sqliteDB.insert return long value on success and -1 on error. The long value indicates the row number for newly inserted row in db. You can check this return value and display toast accordingly.

    Please look at the detailed explanation here, http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert(java.lang.String, java.lang.String, android.content.ContentValues)

    In short, modify your code to be like this,

    private void insertCredentials(RegDetails regDetails){
    
        LoginDB androidOpenDBHelper = new LoginDB(this);
        SQLiteDatabase sqliteDB = androidOpenDBHelper.getWritableDatabase();
    
        ContentValues contentValues = new ContentValues();
        contentValues.put(LoginDB.COLUMN_NAME_USERNAME, rUsername);
        contentValues.put(LoginDB.COLUMN_NAME_PASSWORD, rPasscode);
    
        long affectedColumnid = sqliteDB.insert(LoginDB.TABLE_NAME_CREDENTIALS, null, contentValues);
        if(affectedColumnid != -1){
        Toast.makeText(getApplicationContext(), "Credentials Saved! Please login" + affectedColumnid, Toast.LENGTH_SHORT).show();
         }else{
         // Display error dialog or smthg
         }
        sqliteDB.close();
        finish();
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that there's a set of methods used to pass data from one
I want that part 1 onclick div style changes and part 2 again on
I have an onclick function that I want to add an anchor to the
I have an onClick method set in the xml layout file that triggers the
I inherited an application that used forms to POST data. I am not very
I want the onClick method not only to create a new activity to the
I have the following HtmlHelper method that I want to create a button that
I want to capture onClick events for the trackball on a HTC Hero. This
In the following code, I want to set Onclick Listeners on some elements of
I have a button inside of a gridview's template field. Onclick i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.