我创建了一个登录应用程序,该应用程序从 sql server 登录 id 和密码它可以正常工作以获取正确的登录 id、密码,并且还为空登录字段提供 toast
但是,如果我输入了错误的字段。它没有显示想要的吐司。也许我在错误的地方使用吐司。我的代码是
public void onClick(View v) {
// TODO Auto-generated method stub
ResultSet rs=null;
String id=uid.getText().toString();
String upass=pass.getText().toString();
final String uid1=null;
final ProgressDialog pd=new ProgressDialog(MainActivity.this);
pd.setTitle("Processing");
pd.setMessage("Processing is going on..plz be patient...");
pd.show();
if(id.equals("")&&upass.equals("")){
Toast.makeText(getApplicationContext(), "empty id or password", Toast.LENGTH_SHORT).show();
}
new Thread(){
public void run(){
//defining task for progress dialog for busy.
try{
ResultSet rs=null;
String id=uid.getText().toString();
String upass=pass.getText().toString();
String uid1=null;
if(!id.isEmpty()&&!upass.isEmpty())
try{
initilize();
Statement statement=connect.createStatement();
rs=statement.executeQuery("LOGIN '"+id+"', '"+upass+"'");
List<String>data=new ArrayList<String>();
if(rs.next()){
uid1=rs.getString("PA_NAME");
pd.dismiss();
Intent i=new Intent(getApplicationContext(),SecondActivity.class);
i.putExtra("a", uid1);
startActivity(i);
}
}catch(Exception e){
e.printStackTrace();
}
else
Toast.makeText(MainActivity.this, "invalid id or password", Toast.LENGTH_LONG).show();pd.dismiss();
}catch(Exception e){
}
pd.dismiss();
}}.start();
如果有人建议我在哪里放置错误的登录 ID。在条件语句中。这很紧急。