正在开发一个具有三个不同级别用户的Android应用程序,即管理员,经理和工程师。我想知道如何在登录活动类中编码,因为在sqlite数据库中有一个包含用户名,密码和用户级别字段的登录表。
活动类的代码段如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
// create a instance of SQLite Database
loginDataBaseAdapter=new LoginDataBaseAdapter(this);
loginDataBaseAdapter=loginDataBaseAdapter.open();
// Get The Reference Of Buttons
setBtnLogin((Button)findViewById(R.id.btnLogin));
}
// Methods to handleClick Event of Sign In Button
public void sendMessage(View view)
{
Intent intentLogin=new Intent(getApplicationContext(),MainActivity.class);
startActivity(intentLogin);
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.fragment_main);
dialog.setTitle("Login");
// get the References of views
final EditText username=(EditText)dialog.findViewById(R.id.reg_username);
final EditText password=(EditText)dialog.findViewById(R.id.reg_password);
Button btnLogin=(Button)dialog.findViewById(R.id.btnLogin);
// Set On ClickListener
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// get The User name and Password
String userName=username.getText().toString();
String passWord=password.getText().toString();
// fetch the Password form database for respective user name
String storedPassword=loginDataBaseAdapter.getSingleEntry(userName);
// check if the Stored password matches with Password entered by user
if(passWord.equals(storedPassword))
{
Toast.makeText(MainActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
dialog.dismiss();
}
else
{
Toast.makeText(MainActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
}
}
});
dialog.show();
finish();
onDestroy();
}
@Override
protected void onDestroy() {
super.onDestroy();
// Close The Database
loginDataBaseAdapter.close();
}