Egek92 Egek92 -4 years ago 116
Android Question

How to create EditText fields depending on the spinner option?

Question may seem unclear, I need to create EditTexts depending on the selected spinner option. For instance:



Spinner Options:

<string-array name="spinner_options">
<item>One </item>
<item>Two </item>
<item>Three </item>
<item>Four </item>


spnOptions.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String chosenOption = (String) parent.getItemAtPosition(position);

public void onNothingSelected(AdapterView<?> parent) {}

I have this spinner with 4 options, if the users select 3, 3 EditText will be appear under the spinner. I tried to create 4 EditTexts and set them Invisible and make them visible depending on the choice but it seems like a horrible idea in performance wise. Anyone have another idea.

Answer Source

Create the four EditText in your xml layout with visibility="GONE". Then depending on Spinner selection change visibility to VISIBLE using setVisibility()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download