You are on page 1of 3

Term project

ET716
12/12/2021

Summary
For my term project, I created an app that lets you type down a message and then it will
display the message in another activity. The code that you need is below: The main
activity.java which is easy to follow, the main activity.xml consists of an edit text and a
button. In the hint area, you connect the strings together for the button and the edit text,
the edit text is the edit message string and the button is the send message string. The
display message java code will help the message be sent. The onclick should be
configured for the button.

Emulator This is what the layout should be


Code ACTIVITY_JAVA.XML

ACTIVITY_MAIN.XML

public static final String


EXTRA_MESSAGE =
"com.example.myfirstapp.MESSAGE";
<EditText @Override
protected void onCreate(Bundle
android:id="@+id/editTextTextPersonNam savedInstanceState) {
e"
android:layout_width="wrap_content" super.onCreate(savedInstanceState);

android:layout_height="wrap_content" setContentView(R.layout.activity_main
android:ems="10" );
android:hint="@string/edit_message" }
android:inputType="textPersonName"
android:textColor="#9C27B0" public void sendMessage(View view)
{
tools:layout_editor_absoluteX="32dp" Intent intent = new
Intent(this,
tools:layout_editor_absoluteY="43dp" DisplayMessageActivity.class);
/> EditText editText = (EditText)
findViewById(R.id.editTextTextPersonN
<Button ame);
android:id="@+id/button" String message =
android:layout_width="wrap_content" editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE,
android:layout_height="wrap_content" message);
android:hint="@string/button_send" startActivity(intent);
android:onClick="sendMessage"
android:textColor="#8A2C2C" }
}
app:layout_constraintBaseline_toBaseli
neOf="@+id/editTextTextPersonName"
DisplayMessageActivity.java
tools:layout_editor_absoluteX="287dp"
/> @Override
protected void onCreate(Bundle
savedInstanceState) {

super.onCreate(savedInstanceState);
Strings.xml
setContentView(R.layout.activity_disp
<string name="app_name">My first lay_message);
app</string>
<string name="edit_message">Enter a
message</string> Intent intent = getIntent();
<string String message =
name="button_send">Send</string> intent.getStringExtra(MainActivity.EXT
RA_MESSAGE);
TextView textView =
findViewById(R.id.textView);
textView.setText(message);
}
}

You might also like