Mak wrote:
> Hi.
> I have a spinner with an array of items.
> Now I want to add a blank item
> so that the user has the choice of
> using an element or writes an own entry.
> 
> My main.xml looks like this:
> ....
>     <Spinner android:id="@+id/length"
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:autoText="true"
>         android:drawSelectorOnTop="true">
>     </Spinner>
> .....
> And in my array.xml i have the arrayList
>     <string-array name="Numbers">
>         <item> 555</item>
>         <item> 852</item>
>         <item> 65</item>
>     </string-array>
> 
> And in the .java file it looks like this:
>         Spinner nummer = (Spinner) findViewById(R.id.number);
>         ArrayAdapter<CharSequence> uriAdapter =
> ArrayAdapter.createFromResource(
>                 this, R.array.Numbers,
> android.R.layout.simple_spinner_item);
>         uriAdapter.setDropDownViewResource
> (android.R.layout.simple_spinner_dropdown_item);
>         nummer.setAdapter(uriAdapter);
> 
> My idea was to add not an item but an EditText like this:
> 
>     <string-array name="Numbers">
>         <item> 555</item>
>         <item> 852</item>
>         <item> 65</item>
>         <EditText android:id="@+id/enummer"
>               android:layout_width="fill_parent"
>               android:layout_height="wrap_content"
>               android:autoText="true"
>               android:capitalize="sentences"
>               android:layout_weight="1"
>               android:freezesText="true">
>       </EditText>
>     </string-array>
> 
> but this wouldn't work.

A string-array resource is a list of strings.

> Has anybody an idea what way i can realize that?

An Option That Probably Will Not Work, But Is What You Are Asking:
subclass your Adapter and inject the EditText yourself.

An Option That Will Work, But Isn't What You Asked For: Put a checkbox
to the side of the spinner. Put an EditText in the same spot as the
spinner, but initially invisible. Based on the checkbox toggle, hide the
spinner and show the EditText (or vice versa). This doesn't put the
EditText in the Spinner itself, but does provide a compact means of
allowing the user to either choose from the list or enter in a value.

Android does not have a native combobox widget AFAIK, which is what you
are really after.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com

Android Training on the Ranch! -- Mar 16-20, 2009
http://www.bignerdranch.com/schedule.shtml

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to