-2

I need to Create Multiple Spinner Based on Edittext value.An spinner Must be created dynamically ..for example if i am giving the value 5 in edittext 5 spinner must be created..if anybody know tell me

2

1 Answer 1

0
 edtGiven=(EditText)findViewById(R.id.edtGiven);
       btnSubmit=(Button)findViewById(R.id.btnSubmit);
       final RelativeLayout layout=new RelativeLayout(this);
       linear=(LinearLayout)findViewById(R.id.Linear);
       StringBuffer spinnerBuffer = new StringBuffer();
       final  ArrayList<String> spinnerArray = new ArrayList<String>();
       spinnerArray.add("1");
       spinnerArray.add("3");
       spinnerArray.add("4");
       spinnerArray.add("5");
       spinnerArray.add("6");

       Spinner spinner = new Spinner(MainActivity.this);
        ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, spinnerArray); //selected item will look like a spinner set from XML
        spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinnerArrayAdapter);



       btnSubmit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //int change=Integer.parseInt(EdtValue);
             int ff=-1;
            if(edtGiven.getText().toString().length()>0)
            {
                ff=Integer.parseInt(edtGiven.getText().toString());
            }
            Toast.makeText(getApplicationContext(), "btn", 1000).show();
            for(int i=0;i<ff;i++)
              {
                Toast.makeText(getApplicationContext(), "bfor", 1000).show();
                 Spinner spinner = new Spinner(MainActivity.this);
                  ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_item,spinnerArray);
                spinner.setAdapter(adapter);
                spinner.setPrompt("works");
               linear.addView(spinner);
               Toast.makeText(getApplicationContext(), "bottom", 1000).show();

              }

        }
    });

   }

finally i got answer to create multiple spinner based on my input from edittext

Not the answer you're looking for? Browse other questions tagged or ask your own question.