-4
class Login extends Activity implements OnClickListener{
private EditText user, pass;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String LOGIN_URL = "http://ridgepvt.com/android/loginapp.php";
private static final String TAG_SUCCESS = "success"; private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(Bundle savedInstanceState) {
Button bLogin;
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
user = (EditText)findViewById(R.id.username);
pass = (EditText)findViewById(R.id.password);
bLogin = (Button)findViewById(R.id.login);
bLogin.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login:
String username1 = user.getText().toString();
String password1 = pass.getText().toString();
new AttemptLogin(username1,password1).execute();
default:
break;
}
}
class AttemptLogin extends AsyncTask<String, String, String> {
boolean failure = false;
private String username;
private String password;
public AttemptLogin(String username1, String password1) {
super();
username = username;
password = password;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("Attempting for login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
Log.d("request!", "starting");
JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);
Log.d("Login attempt", json.toString());
success = json.getInt(TAG_SUCCESS);
if (success == 1)
{ Log.d("Successfully Login!", json.toString());
Intent ii = new Intent(Login.this,OtherActivity.class);
startActivity(ii);
finish();
return json.getString(TAG_MESSAGE);
}else{
return json.getString(TAG_MESSAGE);
}
}
catch (JSONException e)
{ e.printStackTrace(); }
return null;
}
protected void onPostExecute(String message)
{ pDialog.dismiss();
if (message != null)
{
Toast.makeText(Login.this, message, Toast.LENGTH_LONG).show();
}
}
}
}
錯誤是邏輯它不會將我的字符串數據傳遞到PHP文件。錯誤是COMING當我在後臺使用GET.TEXT功能,但我想通過重寫構造函數和傳遞數據作爲參數在onclick功能android應用程序登錄數據沒有從我的應用程序傳遞到我的php文件
它仍然沒有工作的用戶名和密碼的 –
Put日誌值 –