Renz Carlo Salanga
Lurker
Hi Please Help Me Because this is My First Time Making Android Application
Heres What Im Trying to do here..
Theres Two Major Component In my Application
1.) TextView - which the text set to "Greetings Appear Here"
2.)Button
When i click the button the TextView text should change to "Hello"
but suddenly my app crashes Please Help Here is My code
Java Class FIle
package renz.com.myfirstapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView message;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
message=(TextView)findViewById(R.id.greetings_view);
}
public void showGreetings()
{
String mes="Hello";
message.setText(mes);
}
}
XML FIle
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android
addingBottom="@dimen/activity_vertical_margin"
android
addingLeft="@dimen/activity_horizontal_margin"
android
addingRight="@dimen/activity_horizontal_margin"
android
addingTop="@dimen/activity_vertical_margin"
tools:context="renz.com.myfirstapp.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greeetings Appear Here"
android:id="@+id/greetings_view" />
<Button
android:text="Show Greetings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/greetings_view"
android
nClick="showGreetings"
/>
</RelativeLayout>
Heres What Im Trying to do here..
Theres Two Major Component In my Application
1.) TextView - which the text set to "Greetings Appear Here"
2.)Button
When i click the button the TextView text should change to "Hello"
but suddenly my app crashes Please Help Here is My code
Java Class FIle
package renz.com.myfirstapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView message;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
message=(TextView)findViewById(R.id.greetings_view);
}
public void showGreetings()
{
String mes="Hello";
message.setText(mes);
}
}
XML FIle
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android
addingBottom="@dimen/activity_vertical_margin"android
addingLeft="@dimen/activity_horizontal_margin"android
addingRight="@dimen/activity_horizontal_margin"android
addingTop="@dimen/activity_vertical_margin"tools:context="renz.com.myfirstapp.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greeetings Appear Here"
android:id="@+id/greetings_view" />
<Button
android:text="Show Greetings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/greetings_view"
android
nClick="showGreetings"/>
</RelativeLayout>