• Uncategorized
  • 0

PAB2018-M3-SI-39-04-M.ZAHIDSYAFNEL

1.3  Menggunakan Elemen TextView

Tugas 1. Menambah beberapa tampilan teks

Buat Project dan element Text View

 

Requirement yang dibutuhkan untuk mengubah nilai atribut

Lalu masukkan kode sesuai dengan buku di class activity_main.xml lalu tekan alt+enter dan pilih create…

Lalu buka folder strings.xml dan masukkan kode yang dikasih dari buku

 

Tugas 2 Menambahkan tautan web aktif dan scrool view

 

Tugas 3 Menggulirkan Beberapa elemen

Menambahkan LinearLayout ke ScrollView

Hasil Akhir :

Source Code :

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=”com.example.zahid.scrollingtext.MainActivity”>

<TextView
android:id=”@+id/article_heading”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@color/colorPrimary”
android:textColor=”@android:color/holo_orange_light”
android:textColorHighlight=”@color/colorAccent”
android:padding=”10dp”
android:textAppearance=”@android:style/TextAppearance.Large”
android:textStyle=”bold”
android:text=”@string/article_title”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintRight_toRightOf=”parent”
app:layout_constraintTop_toTopOf=”parent” />

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/article_subheading”
android:layout_below=”@id/article_heading”
android:padding=”10dp”
android:paddingBottom=”10dp”
android:paddingLeft=”10dp”
android:paddingRight=”10dp”
android:textAppearance=”@android:style/TextAppearance”
android:text=”@string/article_subtitle”
/>

<ScrollView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@id/article_subheading”>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:orientation=”vertical”>

<TextView
android:id=”@+id/article”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@id/article_subheading”
android:lineSpacingExtra=”5sp”
android:text=”@string/article_text”
android:autoLink=”web”
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>

 

Strings.xml

<resources>
<string name=”app_name”>Scrolling Text</string>
<string name=”article_title”>Beatles Anthology Vol. 1</string>

<string name=”article_subtitle”>Behind That Locked Door: Beatles Rarities!</string>

<string name=”article_text”>In a vault deep inside Abbey Road Studios in London — protected by an unmarked, triple-locked, police-alarmed door — are something like 400 hours of unreleased Beatles recordings, starting from June 2, 1962 and ending with the very last tracks recorded for the <i>Let It Be</i> album. The best of the best were released by Apple Records in the form of the 3-volume Anthology series.
For more information, see the Beatles Time Capsule at www.rockument.com.
\n\n
This volume starts with the first new Beatle song, “Free as a Bird” (based on a John Lennon demo, found only on the bootleg <i>The Lost Lennon Tapes Vol. 28</i>, and covers the very earliest historical recordings, outtakes from the first albums, and live recordings from early concerts and BBC Radio sessions.
\n\n
<b>Highlights include:</b>
\n\n
<b><i>Cry for a Shadow</i></b> – Many a Beatle fanatic started down the bootleg road, like I did, with a first listen to this song. Originally titled “Beatle Bop” and recorded in a single session that yielded four songs (the other three featured Tony Sheridan with the Beatles as a backing band), “Cry for a Shadow” is an instrumental written by Lennon and Harrison, which makes it unique to this day. John Lennon plays rhythm guitar, George Harrison plays lead guitar, Paul McCartney plays bass, and Pete Best plays drums. The sessions were produced by Bert Kaempfert in Hamburg, Germany, during the Beatles’ second visit from April through July of 1961 to play in the Reeperbahn-section clubs.
\n\n
<b><i>My Bonnie</i></b> and <b><i>Ain’t She Sweet</i></b> — At the same session, the Beatles played on “My Bonnie” (the first-ever single with Beatles playing), as the backing band for English singer Tony Sheridan, originally a member of the Jets. The popularity of this single in Liverpool brought the Beatles to the attention of Brian Epstein, who worked in the NEMS record store and tried to meet demand for the disc. John Lennon then sings a fine “Ain’t She Sweet” (his first-ever released vocal).
\n\n
<b><i>Searchin</i></b> — A Jerry Leiber – Mike Stoller comedy song that was a hit for the Coasters in 1957, and a popular live favorite of the Beatles. The Coasters also had a hit with “Besame Mucho” and the Beatles covered that song as well. Ringo Starr had by now replaced Pete Best on drums. The high falsetto is George, who also plays a hesitant lead guitar. This is from their first audition for Decca Records in London on Jan 1., 1962, live in the studio. The Grateful Dead would later cover “Searchin” with a similar arrangement, Pigpen doing the Paul vocals. A live version is available on bootlegs featuring the Dead joined by the Beach Boys!
\n\n
<b><i>Love Me Do</i></b> — An early version of the song, played a bit slower and with more of a blues feeling, and a cool bossa-nova beat in middle. Paul had to sing while John played harmonica — a first for the group. Pete Best played drums on this version.
\n\n
<b><i>She Loves You – Till There Was You – Twist and Shout</i></b> — Live at the Princess Wales Theatre by Leicester Square in London, attended by the Queen. “Till There Was You” (by Meredith Wilson) is from the musical The Music Man and a hit for Peggy Lee in 1961. Before playing it, Paul said it was recorded by his favorite American group, “Sophie Tucker” (which got some laughs). At the end, John tells the people in the cheaper seats to clap their hands, and the rest to “rattle your jewelry” and then announces “Twist and Shout” (a song by Bert Russell and Phil Medley that was first recorded in 1962 by the Isley Brothers). A film of the performance shows the Queen smiling at John’s remark.
\n\n
<b><i>Leave My Kitten Alone</i></b> — One of the lost Beatle songs recorded during the “Beatles For Sale” sessions but never released. This song, written by Little Willie John, Titus Turner, and James McDougal, was a 1959 R&amp;B hit for Little Willie John and covered by Johnny Preston before the Beatles tried it and shelved it. A reference to a “big fat bulldog” may have influenced John’s “Hey Bulldog” (Yellow Submarine album), which is a similar rocker.
\n\n
<b><i>One After 909</i></b> — A song recorded for the <i>Let It Be</i> album was actually worked on way back in the beginning, six years earlier. This take shows how they did it much more slowly, with an R&amp;B feel to it.
</string>

</resources>

 

2.1  Membuat dan Memulai Aktivitas

Tugas 1.Membuat Proyek TwoActivities

Membuat Project

 

Menambah source code sesuai dengan buku

 

Lalu mengextract String “send”

Lalu beri nama resource name button_main

 

Lalu buat method onClick

Lalu buat View di main activity

 

Isi source code dari Second Activity.java dan kita menggunakan method onCreate

Tugas 2 .Membuat dan Meluncurkan Aktivitas Kedua

Buat activity_second.xml

Lalu tambahkan source code sesuai dengan buku

 

Lalu modifikasi Android Manifest.xml

 

Lalu Buat modifikasi main activity sesuai dengan source code arahan buku

Hasil Akhir :

Tugas 3 Mengirim data aktivitas utama ke aktivitas ke dua

Menambahkan edit pada activity_main.xlm

Menambahkan String Extra intent pada MainActivity.java

Menambahkan text view pada aktivitas kedua

Memodifikasi activitas kedua agar mendapatkan extra pesan dari activitas utama

Hasil Akhir :

Tugas 4 : Mengembalikan data ke aktivitas Utama

Menambah edit text pada aktifitas kedua

Memuat Intens Respons dalam Activitas kedua

Menambahkan Extra Reply pada main activity

 

Menambahkan Reply message pada MainActivity.java

Hasil Akhir :

 

Source Kode:

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”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.example.android.studycase.MainActivity”>

<TextView
android:id=”@+id/text_header_reply”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/text_header_reply”
android:visibility=”invisible”
android:layout_marginBottom=”@dimen/activity_vertical_margin”
android:textAppearance=”?android:attr/textAppearanceMedium”
android:textStyle=”bold”/>
<TextView
android:id=”@+id/text_message_reply”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@+id/text_header_reply”
android:visibility=”invisible”
android:layout_marginLeft=”@dimen/activity_horizontal_margin”
android:layout_marginStart=”@dimen/activity_horizontal_margin”
android:textAppearance=”?android:attr/textAppearanceMedium” />
<Button
android:id=”@+id/button_main”
android:onClick=”launchSecondActivity”
android:text=”@string/button_name”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”
android:layout_alignParentEnd=”true”
android:layout_alignParentRight=”true”
android:layout_marginBottom=”22dp”
android:layout_marginEnd=”12dp”
android:layout_marginRight=”12dp”/>
<EditText
android:id=”@+id/editText_main”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”
android:layout_toLeftOf=”@+id/button_main”
android:layout_toStartOf=”@+id/button_main”
android:hint=”@string/editText_main” />
</RelativeLayout>

 

Android Manifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.example.android.studycase”>

<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity
android:name=”.SecondActivity”
android:label=”SecondActivity”
android:parentActivityName=”.MainActivity”>
<meta-data
android:name=”android.support.PARENT_ACTIVITY”
android:value=”com.example.android.studycase.MainActivity” />
</activity>
</application>
</manifest>

 

Activity_second.xml

<?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:layout_width=”match_parent”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”.SecondActivity”>
<TextView
android:id=”@+id/text_header”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginBottom=”@dimen/activity_vertical_margin”
android:text=”@string/text_header”
android:textAppearance=”?android:attr/textAppearanceMedium”
android:textStyle=”bold” />
<TextView
android:id=”@+id/text_message”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@+id/text_header”
android:text=”Tes”
android:layout_marginLeft=”@dimen/activity_horizontal_margin”
android:layout_marginStart=”@dimen/activity_horizontal_margin”
android:textAppearance=”?android:attr/textAppearanceMedium” />
<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/button_second”
android:id=”@+id/button_second”
android:layout_alignParentBottom=”true”
android:layout_alignParentRight=”true”
android:layout_alignParentEnd=”true”
android:onClick=”returnReply”/>

<EditText
android:id=”@+id/editText_second”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”
android:layout_toLeftOf=”@+id/button_second”
android:layout_toStartOf=”@+id/button_second”
android:hint=”@string/editText_second” />

</RelativeLayout>

 

Dimens.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<dimen name=”activity_vertical_margin”>16dp</dimen>
<dimen name=”activity_horizontal_margin”>16dp</dimen>
</resources>

 

Strings.xml

<resources>
<string name=”app_name”>StudyCase</string>
<string name=”button_name”>Send</string>
<string name=”text_header”>Message Received</string>
<string name=”editText_main”>Enter Your Message Here</string>
<string name=”button_second”>Reply</string>
<string name=”editText_second”>Enter Your Reply Here</string>
<string name=”text_header_reply”>Reply Received</string>
</resources>

 

SecondActivity.java

package com.example.android.studycase;

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

public class SecondActivity extends AppCompatActivity {
public static final String EXTRA_REPLY =
“com.example.android.twoactivities.extra.REPLY”;

private EditText mReply;

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

Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = (TextView) findViewById(R.id.text_message);
textView.setText(message);

}
public void returnReply(View view) {
String reply = mReply.getText().toString();

Intent replyIntent = new Intent();
replyIntent.putExtra(EXTRA_REPLY, reply);
setResult(RESULT_OK, replyIntent);
finish();
}
}

 

MainActivity.java

package com.example.android.studycase;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private static final String LOG_TAG = MainActivity.class.getSimpleName();
public static final String EXTRA_MESSAGE = “com.example.android.twoactivities.extra.MESSAGE”;

public static final int TEXT_REQUEST = 1;
private EditText mMessageEditText;
private TextView mReplyHeadTextView;
private TextView mReplyTextView;

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

mMessageEditText = (EditText) findViewById(R.id.editText_main);
mReplyHeadTextView = (TextView) findViewById(R.id.text_header_reply);
mReplyTextView = (TextView) findViewById(R.id.text_message_reply);
}

public void launchSecondActivity(View view) {
Log.d(“LOG_TAG”, “Button clicked!”);
Intent intent = new Intent(this, SecondActivity.class);

String message = mMessageEditText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}

public void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == TEXT_REQUEST) {
if (resultCode == RESULT_OK) {
String reply =
data.getStringExtra(SecondActivity.EXTRA_REPLY);

mReplyHeadTextView.setVisibility(View.VISIBLE);
mReplyTextView.setText(reply);
mReplyTextView.setVisibility(View.VISIBLE);
}
}
}
}

 

 

2.3 Memulai Aktivitas dengan Intent Implisit

                Tugas 1. Membuat Proyek dan Layout Baru

Membuat Proyek baru

Menambah source code di file strings.xml

Mengubah layout dan fungsi lain activity main

Hasil layout jika sudah berhasil diubah

 

Tugas 2. Mengimplementasikan “buka situs web”

Mendefinisikan metode open website

Hasil akhir:

 

 

 

 

 

 

 

 

 

 

 

 

M.Zahid Syafnel

I've a dream to be a busineman and a technopreneur

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *