Advertisement
Guest User

Untitled

a guest
Jul 15th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. package homeworkah.dosisoft.com.homeworkah;
  2.  
  3. import android.support.v7.app.ActionBarActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.Menu;
  7. import android.view.MenuItem;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import java.net.URL;
  11. import java.io.BufferedReader;
  12. import java.io.InputStreamReader;
  13. import java.net.MalformedURLException;
  14. import java.io.IOException;
  15.  
  16. public class MainActivity extends ActionBarActivity {
  17.     private Button buttonOK;
  18.     private EditText editText;
  19.  
  20.     @Override
  21.     protected void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.activity_main);
  24.  
  25.         editText = (EditText) findViewById(R.id.editText);
  26.         buttonOK = (Button) findViewById(R.id.buttonOK);
  27.     }
  28.  
  29.     public void onButtonOKClicked(View v){
  30.         URL url = null;
  31.         try{
  32.             url = new URL("http://example.com");
  33.             String readLine = null;
  34.             String sResult = null;
  35.             BufferedReader buffReader = new BufferedReader(new InputStreamReader(url.openStream()));
  36.             while((readLine = buffReader.readLine()) != null) {
  37.                 if(sResult == null){
  38.                     sResult = readLine;
  39.                 }else{
  40.                     sResult = sResult + readLine;
  41.                 }
  42.             }
  43.         }
  44.         catch(MalformedURLException me){
  45.             me.printStackTrace();
  46.         }
  47.         catch(IOException ioe){
  48.             ioe.printStackTrace();
  49.         }
  50.     }
  51.  
  52.     @Override
  53.     public boolean onCreateOptionsMenu(Menu menu) {
  54.         // Inflate the menu; this adds items to the action bar if it is present.
  55.         getMenuInflater().inflate(R.menu.menu_main, menu);
  56.         return true;
  57.     }
  58.  
  59.     @Override
  60.     public boolean onOptionsItemSelected(MenuItem item) {
  61.         // Handle action bar item clicks here. The action bar will
  62.         // automatically handle clicks on the Home/Up button, so long
  63.         // as you specify a parent activity in AndroidManifest.xml.
  64.         int id = item.getItemId();
  65.  
  66.         //noinspection SimplifiableIfStatement
  67.         if (id == R.id.action_settings) {
  68.             return true;
  69.         }
  70.  
  71.         return super.onOptionsItemSelected(item);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement