이 작업 방법에 대한 도움을 받으십시오. 로그인을하고 모든 오류 및 가능한 예외를 인증합니다. 이것은 내 코드입니다.asynctask 안에 토스트
EditText un, pw;
ImageButton login;
TextView error;
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
un=(EditText)findViewById(R.id.txtUsername);
pw=(EditText)findViewById(R.id.txtPassword);
login=(ImageButton)findViewById(R.id.btnLogin);
error=(TextView)findViewById(R.id.errTxt);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new login().execute();
}
});
}
public class login extends AsyncTask{
@Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
//String valid = "1";
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://www.cjcld.org/dvts1/mobile/login.php", postParameters);
String res=response.toString();
// res = res.trim();
res= res.replaceAll("\\s+","");
//error.setText(res);
if(Integer.parseInt(res)>0){
postParameters.add(new BasicNameValuePair("id", res));
String result = null;
try
{
result = CustomHttpClient.executeHttpPost("http://www.cjcld.org/dvts1/mobile/status.php", postParameters);
String res2=result.toString();
res2= res2.replaceAll("\\s+","");
if(Integer.parseInt(res2)>0){
Intent myIntent = new Intent(getApplicationContext(), dashboard.class);
Bundle logval = new Bundle();
logval.putString("uid", res);
logval.putString("did", res2);
myIntent.putExtras(logval);
startActivity(myIntent);
}else{
Toast.makeText(getApplicationContext(),"No Delivery", Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(getApplicationContext(),"Sorry!! Incorrect Username or Password", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_LONG).show();
}
return null;
}
}
토스트가 실행되면 프로그램이 닫히고 오류 메시지가 나타납니다.
고맙습니다. 이것은 내 문제를 해결하는 데 도움이됩니다. –
그래! 이 도움이된다면 내 게시물의 왼쪽 상단에 체크 표시하여 내 게시물을 표시 할 수 있습니다 :-) –
감사합니다 ... 내 인생을 살리십시오 ^^ –