Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button PostButton, GetButton;
- TextView UsernameTextView, PasswordTextView;
- EditText UsernameEditText, PasswordEditText;
- // 192.168.1.210
- // static fields
- private static String URL = "http://192.168.1.210/cpsscripts/total_items.php";
- private static String GET_TOTAL = "gettotal";
- // objetcs
- JSONParser jsonParser ;
- List<NameValuePair> params;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // Views Import
- PostButton = (Button) findViewById(R.id.post_button);
- GetButton = (Button) findViewById(R.id.get_button);
- UsernameEditText = (EditText) findViewById(R.id.username_edittext);
- PasswordEditText = (EditText) findViewById(R.id.password_edittext);
- UsernameTextView = (TextView) findViewById(R.id.username_textView);
- PasswordTextView = (TextView) findViewById(R.id.password_textView);
- // Objects
- // jsonParser = new JSONParser();
- // params = new ArrayList<NameValuePair>();
- //
- //
- // params.add(new BasicNameValuePair("", ""));
- PostButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new GetTotal().execute();
- // try {
- // JSONObject json = jsonParser.getJSONFromURL(URL, params);
- // String res = json.getString("gettotal");
- // UsernameTextView.setText(res);
- // } catch (JSONException e) {
- // e.printStackTrace();
- // }
- }
- });
- }
- private class GetTotal extends AsyncTask<Void, Void, String>{
- @Override
- protected String doInBackground(Void... args) {
- // TODO Auto-generated method stub
- jsonParser = new JSONParser();
- params = new ArrayList<NameValuePair>();
- params.add(new BasicNameValuePair("", ""));
- try {
- JSONObject json = jsonParser.getJSONFromURL(URL, params);
- String res = json.getString("gettotal");
- //UsernameTextView.setText(res);
- System.out.println("Res: " + res);
- return res;
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- @Override
- protected void onPostExecute(String result) {
- // TODO Auto-generated method stub
- super.onPostExecute(result);
- UsernameTextView.setText(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment