我正在使用微调器向Android获取Zone_name值
connectionClass = new ConnectionClass();
zonespinner = (Spinner) findViewById(R.id.Zone);
String query = "select * from t_zone";
try {
Connection con = connectionClass.CONN();
stmt = con.prepareStatement(query);
rs = stmt.executeQuery();
ArrayList<String> data = new ArrayList<String>();
ArrayList<String> dataid = new ArrayList<String>();
while (rs.next()) {
String id = rs.getString("Zone_name");
String zid = rs.getString("Zone_id");
data.add(id);
dataid.add(zid);
}
String[] array = data.toArray(new String[0]);
ArrayAdapter<String> NoCoreAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, data);
zonespinner.setAdapter(NoCoreAdapter);
} catch (SQLException e) {
e.printStackTrace();
}
zonespinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Object item = parent.getItemAtPosition(position);
//Toast.makeText(Database.this, (CharSequence) item, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
现在我想将所选项目值相等的ID存储在另一个数据库表中。请提供一些帮助我如何获取所选项目ID并将该ID存储到另一个表中