Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Famer Buddy

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Prac 3a

import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

String tag= "Android Lifecycle Demonstration";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Log.d(tag, "In the onCreate() event");

public void onStart()

super.onStart();

Log.d(tag, "In the onStart() event");

public void onRestart()

super.onRestart();

Log.d(tag, "In the onRestart() event");

public void onPause ()

super.onPause();

Log.d(tag, "In the onPause() event");

public void onStop()


{

super.onStop();

Log.d(tag, "In the onStop() event");

public void onDestroy()

super.onDestroy();

Log.d(tag, "In the onDestroy() event");

}
Prac 7a

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">
<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:gravity="center_horizontal"

android:text="Input your Name"></TextView>

<TableLayout

android:id="@+id/tableLayout1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:stretchColumns="1">

<TableRow

android:id="@+id/tableRow1"

android:layout_width="match_parent"

android:layout_height="wrap_content">

<TextView

android:id="@+id/textView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="First Name"></TextView>

<EditText

android:id="@+id/etFName"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_marginLeft="5dp">

<requestFocus></requestFocus>

</EditText>

</TableRow>

<TableRow

android:id="@+id/tableRow2"

android:layout_width="match_parent"

android:layout_height="wrap_content">

<TextView

android:id="@+id/textView2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Last Name"></TextView>

<EditText

android:id="@+id/etLName"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="5dp"></EditText>

</TableRow>

</TableLayout>

<Button

android:id="@+id/btnSubmit"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:text="Submit"></Button>

</LinearLayout>

MainActivity.java

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.graphics.Color;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.QuickContactBadge;

import android.widget.TextView;

import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

EditText etFName;

EditText etLName;

Button btnSubmit;

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

etFName = (EditText) findViewById(R.id.etFName);

etLName = (EditText) findViewById(R.id.etLName);

btnSubmit = (Button) findViewById(R.id.btnSubmit);

btnSubmit.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent(getApplicationContext(), ViewActivity.class);

intent.putExtra("fname", etFName.getText().toString());

intent.putExtra("lname", etLName.getText().toString());

startActivity(intent);

});

activity_view2.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"
tools:context=".ViewActivity">

<TextView

android:id="@+id/tvView"

android:layout_width="400dp"

android:layout_height="85dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="20dp"

android:text="Output"

android:textColor="@android:color/bright_blue"

android:textSize="24sp"

android:textStyle="bold"></TextView>

</LinearLayout>

ViewActivity.java

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.TextView;

public class ViewActivity extends AppCompatActivity {

TextView tvView;

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_view);

tvView = (TextView) findViewById(R.id.tvView);

Intent intent = getIntent();

String fName = intent.getStringExtra("fname");

String lName = intent.getStringExtra("lname");

tvView.setText("Your name is: " + fName + " " + lName);

You might also like