A simple doubt [closed]

-1
Hello everyone, I just downloaded an android booklet and I am in doubt about an exercise I will post the image of how it is in the handout and how I did it and I would like someone to explain to me why they are not recognizing the seeMessageButton and OnClickListener commands:

book:

asinandroidstudio_layout:

<?xmlversion="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/name_label"
        />
        <EditText
            android:id="@+id/name_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    <Button
        android:id="@+id/see_message_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/see_message"
        />
    <TextView
        android:id="@+id/show_message_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="@string/hello_message"
        android:textStyle="bold"
        android:textSize="24dp"
        android:visibility="invisible"

        />



</LinearLayout>

as in android studio_layout_ code main:

package com.example.pc_vicl.myapplication;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;

import java.awt.font.TextAttribute;

public class MainActivity extends AppCompatActivity {

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

        final EditText nameEditText=(EditText) findViewById(R.id.name_edit_text);
        seeMessageButton = (Button) findViewById(R.id.see_message_button);
        final TextView showMessageText = (TextView) findViewById(R.id.show_message_text);

        seeMessageButton.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick (View view){
                String name=nameEditText.getEditableText().toString();
                showMessageText.setText(getString(R.string.hello_message, name));
                showMessageText.setVisibility(View.VISIBLE);

            }

        });

    }
}

as in android studio_layout_strings:

<resources>
    <string name="name_label">Nome:</string>
    <string name="see_message">Ver mensagem</string>
    <string name="app_name">Ola Mundo </string>
    <string name="hello_message">Olá, %1$!</string>
</resources>
    
asked by anonymous 13.03.2016 / 01:36

1 answer

1

You are trying to use OnClickListener without doing import , you must add import as follows:

import android.view.View.OnClickListener;

In line 14 of your code, you have to specify the type at the moment you declare seeMessageButton see:

Button seeMessageButton = (Button) findViewById(R.id.see_message_button);

I hope I have helped

    
13.03.2016 / 18:38