如何从微调器中选择值然后插入到 php mysql?我有两个 java 文件。
1.微调器
2.向mysql插入数据
如何合并两个文件??
这是我的 java 代码,任何人都可以帮助我吗?
微调器.java
public class spinner extends Activity implements AdapterView.OnItemSelectedListener { TextView selection; String[] items={"Aceh", "Sumatera Utara","Papua"}; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); selection=(TextView)findViewById(R.id.selection); Spinner spin=(Spinner)findViewById(R.id.spinner); spin.setOnItemSelectedListener(this); ArrayAdapter<String> aa=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,items); aa.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item); spin.setAdapter(aa); } public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { selection.setText(items[position]); } public void onNothingSelected(AdapterView<?> parent) { selection.setText(""); }
}
这个文件 tambah_user.java
这是我tambah_user.java
发送mysql的文件代码 amy body 帮帮我?
public class pasang extends Activity {
EditText nomor_reg, nama, ttl, jam, peruntukan, keterangan, notelp;
TextView status, myLatitude, myLongitude;
Button btnShowLocation, simpan, keluar;
GPSTracker gps;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pasang);
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
// show location button click event
myLatitude = (TextView) findViewById(R.id.mylatitude);
myLongitude = (TextView) findViewById(R.id.mylongitude);
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);
peruntukan = (EditText) findViewById(R.id.txtperuntukan);
keterangan = (EditText) findViewById(R.id.txtketerangan);
notelp = (EditText) findViewById(R.id.txtnotelp);
simpan = (Button) findViewById(R.id.btnsimpan);
keluar = (Button) findViewById(R.id.btnexit);
status = (TextView) findViewById(R.id.txtstatus);
simpan.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
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", jam.getText()
.toString()));
postParameters.add(new BasicNameValuePair("peruntukan",
peruntukan.getText().toString()));
postParameters.add(new BasicNameValuePair("keterangan",
keterangan.getText().toString()));
postParameters.add(new BasicNameValuePair("notelp", notelp
.getText().toString()));
postParameters.add(new BasicNameValuePair("lat", myLatitude
.getText().toString()));
postParameters.add(new BasicNameValuePair("long", myLongitude
.getText().toString()));
/* String valid = "1"; */
String response = null;
try {
response = koneksigangguan.executeHttpPost(
"http://plnskh.zz.mu/android/lapor/pasang.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, Mainmenu.class);
startActivity(a);
finish();
}
}