1. Buat class pendaftaran_user.java
2. Scriptn pendaftaran_user.java
package thefly.org;
import go_antri.org.R;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class pendaftaran_user extends Activity {
public DatePickerDialog myDialog;
EditText nama,ttl,alamat,email,pekerjaan,username,password;
RadioGroup jk;
TextView status;
Button daftar;;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pendaftaran_user);
nama=(EditText)findViewById(R.id.txtnama);
jk=(RadioGroup) findViewById(R.id.jekel);
alamat=(EditText)findViewById(R.id.txtalamat);
email=(EditText)findViewById(R.id.txtemail);
pekerjaan=(EditText)findViewById(R.id.txtpekerjaan);
username=(EditText)findViewById(R.id.textusername2);
password=(EditText)findViewById(R.id.textpassword2);
daftar=(Button)findViewById(R.id.btn_daftar);
status=(TextView)findViewById(R.id.txtstatus2);
daftar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//atur variabel utk menampung pilihan jenis kelamin dalam bentk radio button
String type=null;
switch (jk.getCheckedRadioButtonId()) {
case R.id.pria:
type="1";
break;
case R.id.perempuan:
type="2";
break;
}
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("nama", nama.getText().toString()));
postParameters.add(new BasicNameValuePair("ttl", type));
postParameters.add(new BasicNameValuePair("jk", type));
postParameters.add(new BasicNameValuePair("alamat", alamat.getText().toString()));
postParameters.add(new BasicNameValuePair("email", email.getText().toString()));
postParameters.add(new BasicNameValuePair("pekerjaan", pekerjaan.getText().toString()));
postParameters.add(new BasicNameValuePair("username", username.getText().toString()));
postParameters.add(new BasicNameValuePair("password", password.getText().toString()));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost(CustomHttpClient.URL+"pendaftaran_user.php", postParameters);
String res = response.toString();
res = res.trim();
res = res.replaceAll("\\s+","");
status.setText(res);
if (res.equals("1")) status.setText("Registrasi Gagal !!");
else status.setText("Registrasi Berhasil !! Silahkan Login");
}
catch (Exception e) {
nama.setText(e.toString());
}
}
});
}
public void btn_daftar_Clicked(View v) {
Intent panggil_class = new Intent(this, Login.class);
startActivity(panggil_class);
}
public void btn_login_ulang_Clicked(View v) {
Intent panggil_class = new Intent(this, Login.class);
startActivity(panggil_class);
}
}
3. Buat tampilannya
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#fff">
<!-- Header Starts-->
<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<!-- Logo Start-->
<ImageView android:src="@drawable/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"/>
<!-- Logo Ends -->
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="@layout/footer_repeat"
android:layout_alignParentBottom="true">
</LinearLayout>
<!-- Footer Ends -->
<!-- Registration Form -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/header">
<!-- Full Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Nama Lengkap"/>
<EditText
android:id="@+id/txtnama"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Tanggal-Bulan-Tahun Lahir"/>
<EditText
android:id="@+id/txtttl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<RadioGroup
android:id="@+id/jekel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/pria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pria" />
<RadioButton
android:id="@+id/perempuan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Perempuan" />
</RadioGroup>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Alamat"/>
<EditText android:id="@+id/txtalamat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Email"/>
<EditText android:id="@+id/txtemail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Pekerjaan"/>
<EditText android:id="@+id/txtpekerjaan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<!-- Username Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Username"/>
<EditText android:id="@+id/textusername2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Password"/>
<EditText android:id="@+id/textpassword2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true"
android:layout_marginTop="5dip"/>
<TextView
android:id="@+id/txtstatus2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<!-- Register Button -->
<Button
android:id="@+id/btn_daftar"
style="@style/btnStyleSeagull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="81dp"
android:onClick="btn_daftar_Clicked"
android:text="DAFTAR"
android:textColor="#fff" />
<!-- Link to Login Screen -->
<Button android:id="@+id/link_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:text="Sudah memiliki Akun! Klik Login disini"
android:onClick="btn_login_ulang_Clicked"
android:gravity="center"
android:textSize="20dip"
android:textColor="#025f7c"/>
</LinearLayout>
<!-- Registration Form Ends -->
</RelativeLayout>
</ScrollView>
0 komentar:
Posting Komentar