Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- EditText username;
- EditText password;
- TextView attempts;
- Button lbtn;
- // int count = 5;
- SQLiteDatabase db;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- username = (EditText)findViewById(R.id.edtuname);
- password = (EditText)findViewById(R.id.edtpsw);
- attempts = (TextView)findViewById(R.id.txtcount);
- lbtn = (Button)findViewById(R.id.lbtn);
- db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
- db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name VARCHAR,marks VARCHAR);");
- db.execSQL("INSERT INTO student VALUES('121','sujith','68');");
- lbtn=(Button)findViewById(R.id.lbtn);
- lbtn.setOnClickListener(this);
- }
- @Override
- public void onClick(View v)
- {
- if(username.getText().toString().trim().length()==0||
- password.getText().toString().trim().length()==0)
- {
- showMessage("Error", "Please enter all values");
- return;
- }
- else
- {
- Cursor c=db.rawQuery("SELECT name FROM student WHERE rollno='"+password.getText()+"'", null);
- if(c.moveToFirst())
- {
- if(username.getText().toString().equals(c.getString(0)))
- attempts.setText(c.getString(0)+" Login Successful" );
- else
- attempts.setText(c.getString(0)+" Login Failed" );
- }
- }
- }
- public void showMessage(String title,String message)
- {
- AlertDialog.Builder builder=new AlertDialog.Builder(this);
- builder.setCancelable(true);
- builder.setTitle(title);
- builder.setMessage(message);
- builder.show();
- }
- }
Add Comment
Please, Sign In to add comment