rachmadi

Revised MainActivity

Feb 5th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1.  Button PostButton, GetButton;
  2.     TextView UsernameTextView, PasswordTextView;
  3.     EditText UsernameEditText, PasswordEditText;
  4.    // 192.168.1.210
  5.  
  6.     // static fields
  7.     private static String URL = "http://192.168.1.210/cpsscripts/total_items.php";
  8.     private static String GET_TOTAL = "gettotal";
  9.  
  10.  
  11.     // objetcs
  12.     JSONParser jsonParser ;
  13.     List<NameValuePair> params;
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.  
  20.         // Views Import
  21.       PostButton = (Button) findViewById(R.id.post_button);
  22.         GetButton = (Button) findViewById(R.id.get_button);
  23.         UsernameEditText = (EditText) findViewById(R.id.username_edittext);
  24.         PasswordEditText = (EditText) findViewById(R.id.password_edittext);
  25.         UsernameTextView = (TextView) findViewById(R.id.username_textView);
  26.         PasswordTextView = (TextView) findViewById(R.id.password_textView);
  27.  
  28.  
  29.         // Objects
  30. //          jsonParser = new JSONParser();
  31. //          params = new ArrayList<NameValuePair>();
  32. //   
  33. //   
  34. //          params.add(new BasicNameValuePair("", ""));
  35.      
  36.      
  37.             PostButton.setOnClickListener(new View.OnClickListener() {
  38.                 @Override
  39.                 public void onClick(View v) {
  40.                    
  41.                     new GetTotal().execute();
  42.      
  43. //                  try {
  44. //                      JSONObject json = jsonParser.getJSONFromURL(URL, params);
  45. //                      String res = json.getString("gettotal");
  46. //                      UsernameTextView.setText(res);
  47. //                  } catch (JSONException e) {
  48. //                      e.printStackTrace();
  49. //                  }
  50.                 }
  51.             });
  52.  
  53.  
  54.      }
  55.        
  56.         private class GetTotal extends AsyncTask<Void, Void, String>{
  57.  
  58.             @Override
  59.             protected String doInBackground(Void... args) {
  60.                 // TODO Auto-generated method stub
  61.                 jsonParser = new JSONParser();
  62.                 params = new ArrayList<NameValuePair>();
  63.          
  64.          
  65.                 params.add(new BasicNameValuePair("", ""));
  66.                
  67.                 try {
  68.                     JSONObject json = jsonParser.getJSONFromURL(URL, params);
  69.                     String res = json.getString("gettotal");
  70.                     //UsernameTextView.setText(res);
  71.                     System.out.println("Res: " + res);
  72.                     return res;
  73.                 } catch (JSONException e) {
  74.                     e.printStackTrace();
  75.                 }
  76.                
  77.                 return null;
  78.             }
  79.            
  80.             @Override
  81.             protected void onPostExecute(String result) {
  82.                 // TODO Auto-generated method stub
  83.                 super.onPostExecute(result);
  84.                 UsernameTextView.setText(result);
  85.             }
  86.            
  87.         }
  88.      
  89. }
Advertisement
Add Comment
Please, Sign In to add comment