I am working on code where for example the user selects a fabric called FabricA and when he selects it, it needs to populate an edit Text with FabricA price. i have tried to implement it but i cant get the price to show in the edit text. I stored the name and price in two different arrays. Should i store it in the same array?
Here is my code:
try {
ConnectionHelper conStr = new ConnectionHelper();
connect = conStr.connectionclass();
if (connect == null) {
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
} else {
String query = "select * from cc_fabric";
stmt = connect.prepareStatement(query);
rs = stmt.executeQuery();
ArrayList<String> dataF = new ArrayList<>();
ArrayList<String> dataFP = new ArrayList<>();
while (rs.next()) {
String id = rs.getString("FABRIC_NAME");
String price = rs.getString("FABRIC_UNIT_PRICE");// value of database
dataF.add(id);
dataFP.add(price);
}
ArrayAdapter NoCoreAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, dataF);
Fabric.setAdapter(NoCoreAdapter);
}
} catch (SQLException e) {
e.printStackTrace();
}
Fabric.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String name = Fabric.getSelectedItem().toString();
String price = Fabric.getSelectedItem().toString();
fabricPrice.setText(price);
Toast.makeText(Calc_140_plain.this, name, Toast.LENGTH_SHORT)
.show();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
The code doesnt populate my edit text