<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"
tools:context=".MainActivity" >
<ScrollView
android:layout_marginBottom="50dip"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#999999"
>
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#fff">
<TextView
android:id="@+id/txtMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp"
android:layout_x="3px"
android:layout_y="4px"
android:typeface="sans"
android:textColor="#0000ff"
android:background="#000000"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever">
</TextView>
<ImageView
android:id="@+id/myGambar"
android:layout_centerHorizontal="true"
android:src="@drawable/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TableRow android:id="@+id/TableRow00" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Nama " />
<EditText android:id="@+id/inama" />
</TableRow>
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Usia "/>
<EditText android:id="@+id/iusia" android:inputType="number|numberSigned|numberDecimal" />
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Jenis Kelamin"/>
<RadioGroup
android:id="@+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:text="Laki-laki"
android:id="@+id/radPa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#000">
</RadioButton>
<RadioButton android:text="Perempuan"
android:id="@+id/radPi"
android:layout_width="wrap_content"
android:textColor="#000"
android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="@+id/iBatal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Batal"
/>
<Button android:id="@+id/iOk"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="OK"
android:visibility="visible"
/>
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
inputnama.java
package com.lp2maray.com;
import java.util.Calendar;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.text.Html;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
public class inputnama extends Activity {
EditText txtnama,txtusia;
RadioButton radPa,radPi;
String jk="Laki-laki";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inputnama);
callMarquee();
txtnama= (EditText) findViewById(R.id.inama);
txtusia= (EditText) findViewById(R.id.iusia);
radPa= (RadioButton) findViewById(R.id.radPa);
radPa.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
jk="Laki-laki";
}
});
radPi= (RadioButton) findViewById(R.id.radPi);
radPi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
jk="Perempuan";
}
});
Button btnOk= (Button) findViewById(R.id.iOk);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String nama=txtnama.getText().toString();
String usia=txtusia.getText().toString();
if(nama.length()<1){lengkapi("Nama");}
else if(usia.length()<1){lengkapi("Usia");}
else{
Intent put= new Intent(getBaseContext(), soalsoal.class);
put.putExtra("nama", nama);
put.putExtra("usia", usia);
put.putExtra("jk", jk);
startActivity(put);
}
}
});
Button btnBatal= (Button) findViewById(R.id.iBatal);
btnBatal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
keluar();
}
});
}
public void lengkapi(String item){
new AlertDialog.Builder(this)
.setTitle("Lengkapi Data")
.setMessage("Silakan lengkapi data "+item)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}
public void keluar(){
new AlertDialog.Builder(this)
.setTitle("Menutup Aplikasi")
.setMessage("Terimakasih... Anda Telah Menggunakan Aplikasi Ini")
.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}})
.show();
}
public void keluarYN(){
AlertDialog.Builder ad=new AlertDialog.Builder(inputnama.this);
ad.setTitle("Konfirmasi");
ad.setMessage("Apakah benar ingin keluar?");
ad.setPositiveButton("OK",new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
keluar();
}});
ad.setNegativeButton("No",new OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
}});
ad.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
keluarYN();
return true;
}
return super.onKeyDown(keyCode, event);
}
void callMarquee(){
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit= cal.get(Calendar.MINUTE);
int detik= cal.get(Calendar.SECOND);
int tgl= cal.get(Calendar.DATE);
int bln= cal.get(Calendar.MONTH);
int thn= cal.get(Calendar.YEAR);
String stgl=String.valueOf(tgl)+"-"+String.valueOf(bln)+"-"+String.valueOf(thn);
String sjam=String.valueOf(jam)+":"+String.valueOf(menit)+":"+String.valueOf(detik);
TextView txtMarquee=(TextView)findViewById(R.id.txtMarquee);
txtMarquee.setSelected(true);
String kata="Selamat Datang di Aplikasi Android ..Selamat Mengerjakan /"+stgl+"/"+sjam+" #";
String kalimat=String.format("%1$s",TextUtils.htmlEncode(kata));
txtMarquee.setText(Html.fromHtml(kalimat+kalimat+kalimat));
}
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 1, 0, "Arsip").setIcon(R.drawable.keluar);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
Intent put= new Intent(getBaseContext(), listdataDB.class);
startActivity(put);
return true;
}
return false;
}
String getTime(){
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit= cal.get(Calendar.MINUTE);
int detik= cal.get(Calendar.SECOND);
int tgl= cal.get(Calendar.DATE);
int bln= cal.get(Calendar.MONTH);
int thn= cal.get(Calendar.YEAR);
String stgl=String.valueOf(tgl)+"-"+String.valueOf(bln)+"-"+String.valueOf(thn);
String sjam=String.valueOf(jam)+":"+String.valueOf(menit)+":"+String.valueOf(detik);
String gb=stgl+", "+sjam +" WIB";
return gb;
}
}
/////
NB Contoh Spinner
<Spinner android:id="@+id/spinAgama" android:drawSelectorOnTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />
String[]pilAgama={"Islam","Kristen","Hindu","Budha","Kepercayaan"};
Spinner mySpin = (Spinner) findViewById(R.id.spinAgama);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, pilAgama);
mySpin.setAdapter(adapter);
mySpin.setOnItemSelectedListener( new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0,View arg1, int arg2, long arg3){
int index = mySpin.getSelectedItemPosition();
Toast.makeText(getBaseContext(),"Pilihan Anda : " + pilAgama[index], Toast.LENGTH_SHORT).show();}
public void onNothingSelected(AdapterView<?> arg0){}
});
<Spinner android:id="@+id/spinAgama" android:drawSelectorOnTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />
String[]pilAgama={"Islam","Kristen","Hindu","Budha","Kepercayaan"};
Spinner mySpin = (Spinner) findViewById(R.id.spinAgama);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, pilAgama);
mySpin.setAdapter(adapter);
mySpin.setOnItemSelectedListener( new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0,View arg1, int arg2, long arg3){
int index = mySpin.getSelectedItemPosition();
Toast.makeText(getBaseContext(),"Pilihan Anda : " + pilAgama[index], Toast.LENGTH_SHORT).show();}
public void onNothingSelected(AdapterView<?> arg0){}
});
Tidak ada komentar:
Posting Komentar