用户名和密码应该相同才能删除记录

时间:2017-06-04 11:14:43

标签: android

我正在开发一个基于sqlite的CRUD app.my create和Read是可以的。但是,如果我想删除记录,则记录的用户名和密码应该相同。如果不是,则删除功能不起作用。例如:“如果用户名是123,则密码也应该是123”。如果删除功能没有跳转到代码中的else语句...

这是代码

公共类删除扩展活动{

Button buttonDelete,buttonUpdate;
EditText textDelete ;
TextView logTxt;


DBConnector DBConnector;

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.delete);

    // get Instance  of Database Adapter
    DBConnector =new DBConnector(this);
    DBConnector = DBConnector.open();

    // Get Refferences of Views
    textDelete=(EditText)findViewById(R.id.txtDelete);
    logTxt = (TextView)findViewById(R.id.log);


    buttonDelete=(Button)findViewById(R.id.btnDelete);
    buttonUpdate = (Button)findViewById(R.id.btnUpdate);
    buttonDelete.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {


            String userName=textDelete.getText().toString();


            String storedName= DBConnector.SelectedEntry(userName);


            if(userName.equals(storedName))
            {
                DBConnector.deleteValues(userName);
                Toast.makeText(getApplicationContext(), "record deleted", Toast.LENGTH_LONG).show();

                Intent Main=new Intent(getApplicationContext(),MainActivity.class);
                startActivity(Main);
            }


            else
            {

                Toast.makeText(getApplicationContext(), "No such a user name exists ", Toast.LENGTH_LONG).show();
                Intent Main=new Intent(getApplicationContext(),MainActivity.class);
                startActivity(Main);





            }
        }
    });
    buttonUpdate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent update=new Intent(getApplicationContext(),Update.class);
            startActivity(update);

        }
    });
    logTxt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent log=new Intent(getApplicationContext(),Log.class);
            startActivity(log);

        }
    });

}

}

0 个答案:

没有答案