Praktikum 7 | Intent
Project Name : Intent
Buitl Target : Android 2.2
Application name : Intent
Package name : www.percobaan3.com
Activity : database4
string.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Try Intent - Aplysit</string>
<string name="app_name">Try Intent www.aplysit.com</string>
</resources>
main.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/hello"
/>
</LinearLayout>
Buatlah sebuah file formlogin.xml kemudian masukkan coding dibawah ini:
formlogin.xml :
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RelativeLayout android:id="@+id/widget61"
android:layout_height="76px"
android:background="#ffffff"
android:layout_x="0px"
android:layout_y="0px"
android:layout_width="match_parent">
<TextView android:id="@+id/widget62"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FORM LOGIN"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</TextView>
</RelativeLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/widget30"
android:text="NICK"
android:layout_x="12dip"
android:layout_y="125dip">
</TextView>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/widget31"
android:text="PWD"
android:layout_x="18dip"
android:layout_y="198dip">
</TextView>
<EditText android:layout_height="wrap_content"
android:text="" android:layout_width="179px"
android:textSize="18sp"
android:layout_x="81dip"
android:layout_y="185dip"
android:id="@+id/pass_editText">
</EditText>
<EditText android:layout_height="wrap_content"
android:text=""
android:layout_width="179px"
android:textSize="18sp"
android:layout_x="78dip"
android:layout_y="118dip"
android:id="@+id/name_editText">
</EditText>
<Button android:text="RESET"
android:layout_height="wrap_content"
android:layout_width="92px"
android:layout_x="33dip"
android:layout_y="277dip"
android:id="@+id/reset_btn">
</Button>
<Button android:text="SUBMIT"
android:layout_height="wrap_content"
android:layout_width="92px"
android:layout_x="181dip"
android:layout_y="276dip"
android:id="@+id/submit_btn">
</Button>
</AbsoluteLayout>
UsingIntent.java :
package www.percobaan3.com;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Usingintent extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//Menyusun menu
String[] menu = new String[]{"Login","Exit"};
// Menampilkan menu di LisstMenu
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, menu));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Menangkap nilai text yang dklik
Object o = this.getListAdapter().getItem(position);
String pilihan = o.toString();
tampilkanPilihan(pilihan);
}
protected void tampilkanPilihan(String pilihan) {
//Intent digunakan untuk sebagai pengenal suatu activity
Intent i = null;
if (pilihan.equals("Login")) {
i = new Intent(this, login.class);
}
else if (pilihan.equals("Exit")) {
finish();
}
startActivity(i);
}
}
login.java :
package www.percobaan3.com;
import www.percobaan3.com.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class login extends Activity {
public String nama;
EditText name;
EditText pass;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.formlogin);
name = (EditText) findViewById(R.id.name_editText);
pass = (EditText) findViewById(R.id.pass_editText);
Button reset = (Button) findViewById(R.id.reset_btn);
reset.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
name.setText("");
pass.setText("");
}
});
Button submit = (Button) findViewById(R.id.submit_btn);
submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
nama = name.getText().toString();
Toast.makeText(getApplicationContext(), "Welcome "+nama,
7).show();
}
});
}
}
Hasil Running :
- Praktikum 7 | Intent
- Unknown
- Senin, 15 Juni 2015
- Tidak ada komentar:
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar