Modul Praktikum Tik Iv: Android
Modul Praktikum Tik Iv: Android
ANDROID
NAMA :
NIM :
Activity
Pindah Activity
Buatlah project baru dengan ketentuan berikut ini :
Theme None
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pertama);
addListenerOnButton();
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_kedua);
}
}
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView1"
android:textAppearance="?android:attr/
textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />
</LinearLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView2" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/
android"
package="belajar.android.pindahactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="belajar.android.pindahactivity.PertamaActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /
>
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".KeduaActivity" >
</activity>
</application>
</manifest>
<string name="app_name">PindahActivity</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="textView1">Di Activity Pertama</string>
<string name="button1">Click untuk ke activity lain</string>
<string name="textView2">Di Activity ke dua</string>
</resources>
DIPERIKSA TANGGAL
Kirim Nilai Activity
Buatlah project baru dengan ketentuan berikut ini :
Theme None
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
}
});
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Intent i = getIntent();
// Receiving the Data
String name = i.getStringExtra("name");
String email = i.getStringExtra("email");
}
}
res > layout > activity_pertama.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/textView1" />
<EditText android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:inputType="text"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/textView2" />
<EditText
android:id="@+id/email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:inputType="textEmailAddress" />
<Button
android:id="@+id/btnNextScreen"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:text="@string/btnNextScreen" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:gravity="center"
android:text="@string/textView3"
android:textSize="25sp" />
<TextView android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:textSize="18sp"/>
<TextView android:id="@+id/txtEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:textSize="18sp"/>
<Button
android:id="@+id/btnClose"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:text="@string/btnClose" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/
android"
package="belajar.android.kirimnilaiactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="belajar.android.kirimnilaiactivity.PertamaActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /
>
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".KeduaActivity" >
</activity>
</application>
</manifest>
<string name="app_name">KirimNilaiActivity</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="textView1">"Name: "</string>
<string name="textView2">"Email: "</string>
<string name="btnNextScreen">Kirim ke Activity kedua</string>
<string name="textView3">Data yang dikirim</string>
<string name="btnClose">Close</string>
</resources>
DIPERIKSA TANGGAL
Aplikasi ShareVia
Buatlah project baru dengan ketentuan berikut ini :
Theme None
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
btn_share=(Button) findViewById(R.id.btnShare);
btn_share.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
shareNow();
}
private void shareNow() {
// TODO Auto-generated method stub
Intent sharingIntent=new
Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromH
tml("<p>This is the text that will be shared </p>"));
startActivity(Intent.createChooser(sharingIntent,
"Share using"));
}
}
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/btnShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btnShare" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/
android"
package="com.share.via"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".ShareViaActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /
>
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
DIPERIKSA TANGGAL