public class MyActivity extends ActionBarActivity { EditText username, password; Button login; TextView status; HttpPost httppost; StringBuffer buffer; HttpResponse response; HttpClient httpclient; List<namevaluepair> nameValuePairs; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); setup(); } private void setup() { username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login = (Button) findViewById(R.id.login); status = (TextView) findViewById(R.id.status); login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { switch (arg0.getId()){ case R.id.login: login(); break; } } }); } private void login() { try{ httpclient = new DefaultHttpClient(); httppost = new HttpPost("http://10.0.2.2/akadalogin/sample.php"); nameValuePairs = new ArrayList<namevaluepair>(1); nameValuePairs.add(new BasicNameValuePair("username", username.getText().toString().trim())); nameValuePairs.add(new BasicNameValuePair("password", password.getText().toString().trim())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); response = httpclient.execute(httppost); ResponseHandler<string> responseHandler = new BasicResponseHandler(); final String response = httpclient.execute(httppost, responseHandler); status.setText(""+response); if (response.equalsIgnoreCase("User found")){ startActivity(new Intent(MyActivity.this, UserPage.class)); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)