Android studio tutorial basic in the previous article was about how we know a programming language Activity in android, which at the article I've included an example is to create a project PindahActivity. From the previous article I hope you have understood the basic concept of an Activity that move from one screen to another screen. On this occasion I still continued tutorial discusses the basic android namely Activity where this time when the user moves from the first to the Activity Activity both then will send the value derived from the input that was in the first Activity.
Of that I ask you to open a studio android application and then create a new project with the name KirimNilaiActivity, where the project is eventually contained KirimNilaiActivity java and xml file as follows:
- PertamaActivity.java
- KeduaActivity.java
- activity_pertama.xml
- activity_kedua.xml
- AndroidManifest.xml
Source code PertamaActivity.java
package com.dsoccerupdate.kirimnilaiactivity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class PertamaActivity extends Activity { EditText inputName; EditText inputEmail; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pertama); inputName = (EditText) findViewById(R.id.name); inputEmail= (EditText) findViewById(R.id.email); Button btnNextScreen = (Button) findViewById(R.id.btnNextScreen); btnNextScreen.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { Intent nextScreen = new Intent(getApplicationContext(), KeduaActivity.class); nextScreen.putExtra("name", inputName.getText().toString()); nextScreen.putExtra("email", inputEmail.getText().toString()); startActivity(nextScreen); } }); } }
Source code KeduaActivity.java
package com.dsoccerupdate.kirimnilaiactivity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class KeduaActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_kedua); TextView txtName = (TextView) findViewById(R.id.txtName); TextView txtEmail = (TextView) findViewById(R.id.txtEmail); Button btnClose = (Button) findViewById(R.id.btnClose); Intent i = getIntent(); String name = i.getStringExtra("name"); String email = i.getStringExtra("email"); txtName.setText(name); txtEmail.setText(email); btnClose.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { finish(); } }); } }
Source code 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="Name: "/> <EditText android:id="@+id/name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dip"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Email: "/> <EditText android:id="@+id/email" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dip"/> <Button android:id="@+id/btnNextScreen" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Kirim ke Activity kedua" android:layout_marginTop="15dip"/> </LinearLayout>
Source code activity_kedua.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Data yang dikirim" android:textSize="25dip" android:gravity="center" android:layout_margin="15dip"/> <TextView android:id="@+id/txtName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="15dip" android:textSize="18dip"/> <TextView android:id="@+id/txtEmail" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="15dip" android:textSize="18dip"/> <Button android:id="@+id/btnClose" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="15dip" android:text="Close"/> </LinearLayout>
Source code AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.dsoccerupdate.kirimnilaiactivity" > <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".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>
Similarly, the advanced tutorial of Activity in android programming languages, hopefully this short article can provide a better understanding of the Activity. Look forward to the continuation of the basic studio android tutorial where the next opportunity I will discuss about the fragment in android. Visit the blog tutorial continues android studio, because there will always be the latest news about the world of Android, especially tutorials to develop applications based on Android.
Sports betting system generates +$3,624 profit last week!
ReplyDeleteZ-Code System winning bets and forecasts for MLB, NHL, NBA & NFL...