Here's the thing, I have a layout where I create someviews according to some data I get from a webservice. There are some edittexts, textviews, spinners, etc.
Its kind of a poll, so after I crete the layout and the options I have to fill it and send the data to the server again.
For this I put objects on the spinner, Im using the adapter suggested in this thread https://stackoverflow.com/a/8116756/6323705
My problem is how to get the spinner values at the end? Because when I use this
mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view,
int position, long id) {
User user = adapter.getItem(position);
// Here you can do the action you want to...
//BUT I DONT NEED TO DO ANYTHING HERE, I NEED TO DO IT AFTER ALL FIELDS ARE FULL
}
@Override
public void onNothingSelected(AdapterView<?> adapter) { }
});
it only saves the last spinner values, and per layout I have like 4 or 5 spinners all differents.
To get the data from layout and then send it Im using something like this:
int childs = parent.getChildCount();
for(int i=0;i <= childs;i++){
View v=parent.getChildAt(i);
if (v instanceof EditText) {
EditText et = (EditText) v;
//then save the data in an special Array
}
else if (v instanceof TextView) {
TextView tv = (TextView) v;
//save it in an other Array
}
else if (v instanceof Spinner) {
Spinner sp = (Spinner) v;
//putting OnItemSelectedListener here is not working either
}
How can I do this?