package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class HelloAndroidActivity extends Activity {
    private TextView helloTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hello_android);

        Button sayHelloButton = (Button) findViewById(R.id.sayHello);
        sayHelloButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                EditText nameEditText = 
                        (EditText) findViewById(R.id.name);
                String name = nameEditText.getText().toString();
                helloTextView.setText("Hi " + name + "!");
            }
        });

        helloTextView = (TextView) findViewById(R.id.hello);
        if (savedInstanceState != null) {
            helloTextView.setText(savedInstanceState
                    .getString("greeting"));
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("greeting", helloTextView.getText()
                .toString());
    }
}