Can someone tell me how to change the spinner value after the alert dialog is called ? I'm calling the alert dialog when "Other..." is clicked. I dont know how to replace the "Other..." value with the new one that I have written in the alert dialog.
final Spinner spinnerLessonDuration = (Spinner) findViewById(R.id.spinnerLessonDuration);
final ArrayAdapter<CharSequence> adapterLessonDuration = ArrayAdapter.createFromResource(this, R.array.lessonDuration, android.R.layout.simple_spinner_item);
adapterLessonDuration.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerLessonDuration.setAdapter(
new NothingSelectedSpinnerAdapter(
adapterLessonDuration,
R.layout.contact_spinner_row_nothing_selected_lesson_duration, this));
spinnerLessonDuration.setOnItemSelectedListener(new setOnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
System.out.println("2 " + spinnerLessonDuration.getSelectedItem());
if (spinnerLessonDuration.getSelectedItem() != null && "Other...".equals(spinnerLessonDuration.getSelectedItem().toString()))
{
View view1 = (LayoutInflater.from(MainActivity.this)).inflate(R.layout.user_input, null);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
alertBuilder.setView(view1);
final EditText userInput = (EditText) view1.findViewById(R.id.userinput);
alertBuilder.setCancelable(true)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//EditText valueView = (EditText) view1.findViewById(R.id.license_value); //here
if (userInput == null) Log.d("AA", "NULL");
else {
String value = userInput.getText().toString();
Log.i(value, "1");
}
}
});
Dialog dialog = alertBuilder.create();
dialog.show();
}
}
}
);
FIXED IT!
Problem was that the arrayList from R.array was immutable :)