gpt4 book ai didi

java - 如何从spinner android中选择值然后插入到mysql?

转载 作者:行者123 更新时间:2023-11-30 01:15:55 24 4
gpt4 key购买 nike

如何从微调器中选择值然后插入到 php mysql?我有两个 java 文件。

1.旋转器

2.向mysql插入数据

如何合并两个文件?

这是我的java代码,有人帮助我吗?

  1. spinner.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("");
    }

    }

  2. 此文件 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();
}

}

最佳答案

Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
postParameters.add(new BasicNameValuePair("YourParameter",mySpinner.getSelectedItem().toString());

关于java - 如何从spinner android中选择值然后插入到mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19063603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com