package com.example.helloandroid;

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

public class HelloAndroidActivity extends Activity {
    private static String TAG = "HelloAndroidActivity";

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

        // Lookup the button and add a listener for button clicks
        Button sayHelloButton = (Button) findViewById(R.id.sayHello);
        sayHelloButton.setOnClickListener(new MyButtonListener());
    }

    class MyButtonListener implements View.OnClickListener {
        public void onClick(View v) {
            // Lookup the gui controls
            EditText nameEditText = (EditText) findViewById(R.id.name);
            TextView helloTextView = (TextView) findViewById(R.id.hello);

            // Retrieve the name from the EditText box
            String name = nameEditText.getText().toString();
            // Say 'Hello' in the TextView
            helloTextView.setText("Hi " + name + "!");

            // Log the name
            Log.v(TAG, "name = " + name);
        }
    }
}