Cleint Server 14 Membuat transaksi pada aplikasi
Assalam'alaikum Warohmatulahi Wabarokatu..
kali ini saya akan membagikan lanjutan dari cleint server yang saya buat sebelumnya, kali ini tampilannya agak berbeda dari sebelum-sebelumnya Aplikasi ini saya beri judul "APLIKASI PENCARIAN RUMAH KOST BERBASIS ANDROID"
1. Tampilan Pesan
1. Tampilan Pesan
Coding xmlnya :
<?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">
<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:textColor="#FF000000"
android:text="Id Pemesan" />
<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:textColor="#FF000000"
android:text="Nama Pemesan" />
<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">
</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:textColor="#FF000000"
android:text="Status Bayar " />
<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:textColor="#FF000000"
android:text="Perbulan" />
<RadioButton
android:id="@+id/perempuan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF000000"
android:text="Perhari" />
</RadioGroup>
</TableRow>
<TableRow
android:id="@+id/widget143"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</TableRow>
<TableRow
android:id="@+id/widget146"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</TableRow>
<TableRow
android:id="@+id/widget149"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</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>
Coding Javanya :
package com.example.kost_app;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint("NewApi") public class Pesan extends Activity {
EditText ktp,nama;
RadioGroup jk;
TextView status;
Button simpan;
/** Called when the activity is first created. */
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pesan);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
ktp=(EditText)findViewById(R.id.txtnomorktp);
nama=(EditText)findViewById(R.id.txtnama);
jk=(RadioGroup) findViewById(R.id.jekel);
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="Perbulan";
break;
case R.id.perempuan:
type="Perhari";
break;
}
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("id_pemesan", ktp.getText().toString()));
postParameters.add(new BasicNameValuePair("nama_lgkp", nama.getText().toString()));
postParameters.add(new BasicNameValuePair("status_bayar", type));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.100.163/kost/pesan_kamar.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) {
nama.setText(e.toString());
}
}
});
}
public void keluar (View theButton)
{
Intent a = new Intent (this,Login.class);
startActivity(a);
}
}
Komentar
Posting Komentar