-1
Hello guys I just downloaded an android booklet and I’m doubtful about an exercise I will post the pictures of how you are in the booklet and how I did and I would like someone to explain to me why you are not recognizing the commands seeMessageButton and Onclicklistener:
as is in android studio_layout:
<?xml version="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 it is in android studio_layout_main code:
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);
}
});
}
}
how is 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>
Add the codes directly here, editing your question, otherwise it is difficult to reproduce your code to find a solution. And explain better the problem you’re facing.
– user28595
thanks for the tip
– Vinicius Clemente
What mistake are you making? It was not very clear in the question. And explain what you are trying to do, just by codes can not know.
– user28595
does not recognize the command seeMessageButton nen the Onclicklistener
– Vinicius Clemente
Probably because it is
final
. Declare theEditText
and theTextView
as parametrics of the class.– user28595
forgive my ignorance but how can I do it ?
– Vinicius Clemente
Forget, run again, no apparent error in code.
– user28595