Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am doing a sample application where I need to show an item from edittext to a spinner. The same has to be added to the database.

This is my spinner populating code :

Java
final DBAdapter db = new DBAdapter(this);
db.open();
Spinner spin = (Spinner) findViewById(R.id.spinner1);
AdapterCountries = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);
AdapterCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(AdapterCountries);

Cursor cursor = db.getAllTitles1();
while (cursor.moveToNext())
{
    results=cursor.getString(2);
    AdapterCountries.add(results);
}
db.close();


Can anyone help me?
Thanks in advance!
Posted
Updated 12-Apr-11 1:20am
v2

1 solution

// get the value from the edittext
EditText edit = findViewById(R.id.edit);

String str =(String)edit.getText().tostring();

Spinner spin =(Spinner) findViewById(R.id.spinner1);

ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,str);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spin.setAdapter(spinnerArrayAdapter);


try this , hope this wil solve..
 
Share this answer
 
Comments
ezhilsigamani 12-Apr-11 8:06am    
thanks for your reply @sajay nambiar....
But i need get to display the input item from edittext to spinner... the same that has to store it in the database...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900