Selasa, 07 November 2017

Cara Buat Project Clent Server input akta, Regis & Login DatabaseMYSQL Dengan Aplikasi Eclipse Adt






CustomHttpClient.java
package com.wilis;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.URI;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

public class CustomHttpClient {
/** The time it takes for our client to timeout */
public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds

/** Single instance of our HttpClient */
private static HttpClient mHttpClient;

/**
* Get our single instance of our HttpClient object.
*
* @return an HttpClient object with connection parameters set
*/
private static HttpClient getHttpClient() {
if (mHttpClient == null) {

mHttpClient = new DefaultHttpClient();
final HttpParams params = mHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
}
return mHttpClient;
}

/**
* Performs an HTTP Post request to the specified url with the
* specified parameters.
*
* @param url The web address to post the request to
* @param postParameters The parameters to send via the request
* @return The result of the request
* @throws Exception
*/
public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters)
throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpPost request = new HttpPost(url);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();

String result = sb.toString();
return result;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

/**
* Performs an HTTP GET request to the specified url.
*
* @param url The web address to post the request to
* @return The result of the request
* @throws Exception
*/

public static String executeHttpGet(String url) throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();

String result = sb.toString();
return result;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}
}
daftar_akta.java
package com.wilis;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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.widget.RadioGroup;
import android.widget.TextView;

public class daftar_akta extends Activity {

EditText
nomor_reg,nama,ttl,jam,anak_ke,ayah_nama,ayah_umur,ayah_pekerjaan,ayah_alamat,ibu_nama
,ibu_umur,ibu_pekerjaan,ibu_alamat;
RadioGroup jk;
TextView status;
Button simpan,keluar;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.daftar_akta);

nomor_reg = (EditText)findViewById(R.id.txtnomor_reg);
nama=(EditText)findViewById(R.id.txtnama);
ttl=(EditText)findViewById(R.id.txtttl);
jam=(EditText)findViewById(R.id.txtjam);
jk=(RadioGroup) findViewById(R.id.jekel);
anak_ke = (EditText) findViewById (R.id.txtanak_ke);
ayah_nama = (EditText)findViewById(R.id.txtayah_nama);
ayah_umur = (EditText)findViewById(R.id.txtayah_umur);
ayah_pekerjaan = (EditText)findViewById(R.id.txtayah_pekerjaan);
ayah_alamat = (EditText)findViewById(R.id.txtayah_alamat);
ibu_nama = (EditText)findViewById(R.id.txtibu_nama);
ibu_umur = (EditText)findViewById(R.id.txtibu_umur);
ibu_pekerjaan = (EditText)findViewById(R.id.txtibu_pekerjaan);
ibu_alamat = (EditText)findViewById(R.id.txtibu_alamat);


simpan=(Button)findViewById(R.id.btnsimpan);
keluar=(Button)findViewById(R.id.btnexit);
status=(TextView)findViewById(R.id.txtstatus);

simpan.setOnClickListener(new View.OnClickListener() {


@Override

public void onClick(View v) {

// TODO Auto-generated method stub

//atur variabel utk menampung pilihan jenis kelamin
String type=null;
switch (jk.getCheckedRadioButtonId()) {
case R.id.pria:
type="Pria";
break;
case R.id.perempuan:
type="Perempuan";
break;
}


ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("nomor_reg",
nomor_reg.getText().toString()));
postParameters.add(new BasicNameValuePair("nama", nama.getText().toString()));
postParameters.add(new BasicNameValuePair("ttl",ttl.getText().toString()));
postParameters.add(new BasicNameValuePair("jam",ttl.getText().toString()));
postParameters.add(new BasicNameValuePair("jekel", type));
postParameters.add(new BasicNameValuePair("anak_ke",
anak_ke.getText().toString()));
postParameters.add(new BasicNameValuePair("ayah_nama",
ayah_nama.getText().toString()));

postParameters.add(new BasicNameValuePair("ayah_umur",
ayah_umur.getText().toString()));
postParameters.add(new BasicNameValuePair("ayah_pekerjaan",
ayah_pekerjaan.getText().toString()));
postParameters.add(new BasicNameValuePair("ayah_alamat",
ayah_alamat.getText().toString()));
postParameters.add(new BasicNameValuePair("ibu_nama",
ibu_nama.getText().toString()));
postParameters.add(new BasicNameValuePair("ibu_umur",
ibu_umur.getText().toString()));
postParameters.add(new BasicNameValuePair("ibu_pekerjaan",
ibu_pekerjaan.getText().toString()));
postParameters.add(new BasicNameValuePair("ibu_alamat",
ibu_alamat.getText().toString()));

/* String valid = "1";*/

String response = null;

try {

response = CustomHttpClient.executeHttpPost("http://10.0.2.2/akta/daftar_akta.php",
postParameters);

String res = response.toString();

res = res.trim();

res = res.replaceAll("\\s+","");

status.setText(res);


if (res.equals("1")) status.setText("Data tidak Tersimpan Ke server");

else status.setText("Data berhasil disimpan ke server");

}

catch (Exception e) {

nomor_reg.setText(e.toString());

}

}


});
}

public void keluar (View theButton)
{
Intent a = new Intent (this,menulayanan.class);
startActivity(a);
}
}

daftar_user.java

package com.wilis;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
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.widget.RadioGroup;
import android.widget.TextView;
public class daftar_user extends Activity {

EditText ktp,nama,ttl,alamat,agama,pekerjaan,username,password;
RadioGroup jk;
TextView status;
Button simpan;


/** Called when the activity is first created. */

@Override


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.daftar_user);


ktp=(EditText)findViewById(R.id.txtnomorktp);
nama=(EditText)findViewById(R.id.txtnama);
ttl=(EditText)findViewById(R.id.txtttl);
jk=(RadioGroup) findViewById(R.id.jekel);
alamat=(EditText)findViewById(R.id.txtalamat);
agama=(EditText)findViewById(R.id.txtagama);
pekerjaan=(EditText)findViewById(R.id.txtpekerjaan);
username=(EditText)findViewById(R.id.txtusername);
password=(EditText)findViewById(R.id.txtpassword);


simpan=(Button)findViewById(R.id.btnsimpan);
// keluar=(Button)findViewById(R.id.btnexit);
status=(TextView)findViewById(R.id.txtstatus);

simpan.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {


// TODO Auto-generated method stub

//atur variabel utk menampung pilihan jenis kelamin
String type=null;
switch (jk.getCheckedRadioButtonId()) {
case R.id.pria:
type="Pria";
break;
case R.id.perempuan:
type="Perempuan";
break;
}


ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("nomor_ktp",
ktp.getText().toString()));
postParameters.add(new BasicNameValuePair("nama",
nama.getText().toString()));
postParameters.add(new
BasicNameValuePair("ttl",ttl.getText().toString()));
postParameters.add(new BasicNameValuePair("alamat",
alamat.getText().toString()));
postParameters.add(new BasicNameValuePair("jekel", type));
postParameters.add(new BasicNameValuePair("agama",
agama.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("http://10.0.2.2/akta/daftar_user.php",
postParameters);

String res = response.toString();

res = res.trim();

res = res.replaceAll("\\s+","");

status.setText(res);

if (res.equals("1")) status.setText("Data tidak Tersimpan Ke server");

else status.setText("Data berhasil disimpan ke server");


}

catch (Exception e) {

username.setText(e.toString());

}

}


});
}

public void keluar (View theButton)
{
Intent a = new Intent (this,login.class);
startActivity(a);
}
}

login.java
package com.wilis;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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.widget.TextView;

public class login extends Activity {
/** Called when the activity is first created. */
EditText username,password;
TextView status;
Button login,daftar;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);

username=(EditText) findViewById(R.id.txtusername);
password=(EditText) findViewById(R.id.txtpassword);
status=(TextView) findViewById (R.id.txtstatus);

login=(Button) findViewById (R.id.btnlogin);
daftar=(Button) findViewById (R.id.btndaftar);

login.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub


ArrayList<NameValuePair> postParameters = new
ArrayList<NameValuePair>();

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("http://10.0.2.2/akta/check.php",
postParameters);

String res = response.toString();

res = res.trim();

res = res.replaceAll("\\s+","");

status.setText(res);

if (res.equals("1"))
{
status.setText("Correct Username or Password");
berhasil(v);


}
else {
status.setText("Sorry!! Wrong Username or Password Entered");

}
}

catch (Exception e) {

status.setText(e.toString());

}

}

});

// penutup buka dari public void onCreate
}




public void daftar (View theButton)
{
Intent d = new Intent (this,daftar_user.class);
startActivity(d);

}


// apabila user berhasil login.

public void berhasil (View theButton)
{
Intent s = new Intent (this, menulayanan.class);
startActivity(s);
}

}
menulayanan.java
package com.wilis;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
//import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class menulayanan extends ListActivity {

/** Called when the activity is first created. */

public void onCreate(Bundle icicle) {
super.onCreate(icicle);

// Create an array of Strings, that will be put to our ListActivity
String[] menulayanan = new String[] { "Identitas Warga", "Exit"};

//Menset nilai array ke dalam list adapater sehingga data pada array akan

dimunculkan dalam list

this.setListAdapter(new ArrayAdapter<String>(this,

android.R.layout.simple_list_item_1,menulayanan));

}

@Override
/**method ini akan mengoveride method onListItemClick yang ada pada class List
Activity
* method ini akan dipanggil apabilai ada salah satu item dari list menu yang dipilih
*/
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
// Menangkap nilai text yang dklik
Object o = this.getListAdapter().getItem(position);
String pilihan = o.toString();
// Menampilkan hasil pilihan menu dalam bentuk Toast
tampilkanPilihan(pilihan);
}

/**
* Tampilkan Activity sesuai dengan menu yang dipilih
*
*/
protected void tampilkanPilihan(String pilihan) {
try {
//Intent digunakan untuk sebagai pengenal suatu activity
Intent i = null;
if (pilihan.equals("")) {
i = new Intent(this, login.class);
} else if (pilihan.equals("")) {
i = new Intent(this, login.class);
} else if (pilihan.equals("Identitas Warga")) {
i = new Intent(this, daftar_akta.class);
} else if (pilihan.equals("")) {
i = new Intent(this, login.class);
} else if (pilihan.equals("Exit")) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure want to Exit?")

.setCancelable(false).setPositiveButton("Yes",

new

DialogInterface.OnClickListener() {

public void

onClick(DialogInterface dialog,

int id) {
Intent exit = new

Intent(
Intent.ACTION_MAIN);

exit.addCategory(Intent.CATEGORY_HOME);

exit

.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(exit);
}
}).setNegativeButton("No",
new

DialogInterface.OnClickListener() {

public void

onClick(DialogInterface dialog,

int id) {
dialog.cancel();
}
}).show();

} else {
Toast.makeText(this,"Anda Memilih: " + pilihan + " ,

Actionnya belum dibuat", Toast.LENGTH_LONG).show();

}
startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Di atas adalah coding file java yang lengkap dan selajutnya kita buat class xml file nya seperti di
bawah ini
Daftar_akta.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView

android:id="@+id/widget124"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/widget124"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="@+id/widget125"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow
android:id="@+id/widget126"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget127"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nomor Register" />
<EditText
android:id="@+id/txtnomor_reg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget129"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget130"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama" />
<EditText
android:id="@+id/txtnama"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>

<TableRow
android:id="@+id/widget132"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</TableRow>
<TableRow
android:id="@+id/widget135"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget136"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="T.T.L" />
<EditText
android:id="@+id/txtttl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/w"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget136"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jam" />
<EditText
android:id="@+id/txtjam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget138"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget139"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jenis Kelamin " />
<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>
</TableRow>
<TableRow
android:id="@+id/widget143"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget144"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anak yang Ke-" />
<EditText
android:id="@+id/txtanak_ke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/wiet146"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget147"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adalah benar anak " />
<TextView
android:id="@+id/widget147"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kandung dari " />
</TableRow>
<TableRow
android:id="@+id/wit146"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget1473"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="AYAH" />
</TableRow>
<TableRow
android:id="@+id/widget149"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget150"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama" />
<EditText
android:id="@+id/txtayah_nama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget152"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget153"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Umur" />
<EditText
android:id="@+id/txtayah_umur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget343"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget450"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pekerjaan" />
<EditText
android:id="@+id/txtayah_pekerjaan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow

android:id="@+id/widget943"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget950"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alamat" />
<EditText
android:id="@+id/txtayah_alamat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/wit146"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget1373"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IBU KANDUNG" />
</TableRow>
<TableRow
android:id="@+id/widget139"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget130"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama" />
<EditText
android:id="@+id/txtibu_nama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget1352"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget1353"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Umur" />
<EditText

android:id="@+id/txtibu_umur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget11343"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget13450"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pekerjaan" />
<EditText
android:id="@+id/txtibu_pekerjaan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget13943"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget950"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alamat" />
<EditText
android:id="@+id/txtibu_alamat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/widget125"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow
android:id="@+id/widget155"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btnsimpan"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="SIMPAN" />
<Button
android:id="@+id/btnexit"
android:onClick="keluar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E X I T" />
</TableRow>
</TableLayout>
<TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>

Daftar_user.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/widget124"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/widget124"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="@+id/widget125"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow
android:id="@+id/widget126"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget127"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nomor KTP" />
<EditText
android:id="@+id/txtnomorktp"
android:layout_width="fill_parent"

android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget129"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget130"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama" />
<EditText
android:id="@+id/txtnama"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget132"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget133"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="T.T.L" />
<EditText
android:id="@+id/txtttl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget135"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget136"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alamat" />
<EditText
android:id="@+id/txtalamat"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget138"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget139"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jenis Kelamin " />
<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>
</TableRow>
<TableRow
android:id="@+id/widget143"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget144"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Agama" />
<EditText
android:id="@+id/txtagama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget146"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/widget147"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pekerjaan" />
<EditText
android:id="@+id/txtpekerjaan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget149"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget150"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="@+id/txtusername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget152"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget153"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="@+id/txtpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:password="True"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/widget125"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow

android:id="@+id/widget155"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btnsimpan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIMPAN" />
<Button
android:id="@+id/btnexit"
android:onClick="keluar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E X I T" />
</TableRow>
</TableLayout>
<TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widg37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="@+id/widget37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<TableRow
android:id="@+id/widget45"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget47"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username :" />

<EditText
android:id="@+id/txtusername"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="@+id/widget46"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget55"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password :" />
<EditText
android:id="@+id/txtpassword"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text=""
android:password="True"
android:textSize="18sp" />
</TableRow>
</TableLayout>

<TableLayout
android:id="@+id/w7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:id="@+id/widget65"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btnlogin"
android:onClick="login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="L O G I N" />
<Button
android:id="@+id/btndaftar"
android:onClick="daftar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DAFTAR" />
</TableRow>
</TableLayout>
<TextView

android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wilis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".login" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="Tambah user pengguna" android:name=".daftar_user" >
</activity>
<activity android:label="Menu Layanan" android:name=".menulayanan" >
</activity>
<activity android:label="Isi Identitas Warga" android:name=".daftar_akta" >
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

Yang di atas adalah coding lengkap dari android parcing ke web server, dan jangan lupa buatkan
file php nya dan databasenya nama database nya adalah (akta dengan 2 table di dalam yaitu table
user dan daftar akta)
Dan di bawah ini adalah file php nya
Check.php
<?php

$username=@$_POST['username'];
$password=@$_POST['password'];

$conn = mysql_connect("localhost","root","");
mysql_select_db("akta");

$query = "SELECT * FROM user WHERE username = '$username' AND password
='$password'";
$result = mysql_query($query) or die("Unable to verify user because : " .
mysql_error());


if (mysql_num_rows($result) == 1){
echo 1;
}
else {
// print status message
echo 0;
}
?>
Daftar_akta.php
<?php
$nomor_reg=@$_POST['nomor_reg'];

$nama=@$_POST['nama'];
$ttl=@$_POST['ttl'];
$jam=@$_POST['jam'];
$jekel=@$_POST['jekel'];
$anak_ke=@$_POST['anak_ke'];
$ayah_nama=@$_POST['ayah_nama'];
$ayah_umur=@$_POST['ayah_umur'];
$ayah_pekerjaan=@$_POST['ayah_pekerjaan'];
$ayah_alamat=@$_POST['ayah_alamat'];
$ibu_nama=@$_POST['ibu_nama'];
$ibu_umur=@$_POST['ibu_umur'];
$ibu_pekerjaan=@$_POST['ibu_pekerjaan'];
$ibu_alamat=@$_POST['ibu_alamat'];

$conn = mysql_connect("localhost","root","");
mysql_select_db("akta");

$query = ("INSERT INTO daftar_akta
(nomor_reg,nama,ttl,jam,jekel,anak_ke,ayah_nama,ayah_umur,ayah_pekerjaan,ayah_ala
mat,ibu_nama,ibu_umur,ibu_pekerjaan,ibu_alamat) values
('$nomor_reg','$nama','$ttl','$jam','$jekel','$anak_ke','$ayah_nama','$ayah_umur','$ayah
_pekerjaan','$ayah_alamat','$ibu_nama','$ibu_umur','$ibu_pekerjaan','$ibu_alamat')");
$result = mysql_query($query) or die("REPORT...Gagal Query Simpan Data.");

if (mysql_num_rows($result) == 1){
echo 1;
}
else {
// print status message
echo 0;

}

?>
Daftar_user.php
<?php
$nomor_ktp=@$_POST['nomor_ktp'];
$nama=@$_POST['nama'];
$ttl=@$_POST['ttl'];
$alamat=@$_POST['alamat'];
$jekel=@$_POST['jekel'];
$agama=@$_POST['agama'];
$pekerjaan=@$_POST['pekerjaan'];
$username=@$_POST['username'];
$password=@$_POST['password'];

$conn = mysql_connect("localhost","root","");
mysql_select_db("akta");

$query = "INSERT INTO user
(nomor_ktp,nama,ttl,alamat,jekel,agama,pekerjaan,username,password) values
('$nomor_ktp','$nama','$ttl','$alamat','$jekel','$agama','$pekerjaan','$username','$passw
ord')";
$result = mysql_query($query) or die("REPORT...Gagal Query Simpan Data.");

if (mysql_num_rows($result) == 1){
echo 1;
}
else {

// print status message
echo 0;
}

?>
Hasil Output Nya yang pertama dari login android


Hasil Output Regis Atau Daftar


 Hasil Output yang Terakhir hasrus Tampil di dalam server seperti ini dan agar supayah
memperidah tampilan seperti di bawah maka saya sarankan untuk download bootstrap admin



0 komentar:

Posting Komentar