Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package homeworkah.dosisoft.com.homeworkah;
- import android.support.v7.app.ActionBarActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.Button;
- import android.widget.EditText;
- import java.net.URL;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.io.IOException;
- public class MainActivity extends ActionBarActivity {
- private Button buttonOK;
- private EditText editText;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- editText = (EditText) findViewById(R.id.editText);
- buttonOK = (Button) findViewById(R.id.buttonOK);
- }
- public void onButtonOKClicked(View v){
- URL url = null;
- try{
- url = new URL("http://example.com");
- String readLine = null;
- String sResult = null;
- BufferedReader buffReader = new BufferedReader(new InputStreamReader(url.openStream()));
- while((readLine = buffReader.readLine()) != null) {
- if(sResult == null){
- sResult = readLine;
- }else{
- sResult = sResult + readLine;
- }
- }
- }
- catch(MalformedURLException me){
- me.printStackTrace();
- }
- catch(IOException ioe){
- ioe.printStackTrace();
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement