I am using a spinner in several places in my program, but I will stick with one case.
I have two xml files -- small_new_system and new_system. They both have the a spinner that is named state_spinner.
The odd thing is that when I use this code on a tablet running 3.2, which uses new_system, they are displayed but when I put the app on my phone that is running 2.1, which uses small_new_system, they do not show up. The items are in the spinner list, but there is no text being displayed. I have tried naming the spinners differently, as well as not using a custom spinner layout.
The other odd thing is that when I use the identical layouts, which do not look very good, on the small device they are not populated with the text either.
Thank you for any help! My code is as follows:
Code to populate the spinner:
states = (Spinner) findViewById(R.id.state_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter
.createFromResource(this, R.array.states,
R.layout.spinner_layout);
adapter.setDropDownViewResource(R.layout.spinner_layout);
states.setAdapter(adapter);
states.setOnItemSelectedListener(new MyItemsOnSelectListener());`
Spinner in small_new_system:
<Spinner
android:id="#+id/state_spinner"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_below="#+id/city_edit"
android:layout_margin="5dp"
android:layout_alignParentRight="true"
android:inputType="textPersonName"
android:textSize="40dp" >
</Spinner>
Spinner in new_system:
<Spinner
android:id="#+id/state_spinner"
android:layout_width="500dp"
android:layout_height="75dp"
android:layout_below="#+id/city_edit"
android:layout_margin="10dp"
android:layout_alignParentRight="true"
android:textSize="60dp" >
</Spinner>`
Code in custom spinner:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinnerTarget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#00000000"
android:textSize="40dp" >
</TextView>`
Try removing:
android:inputType="textPersonName"
from small_new_system. Then it would look like:
<Spinner
android:id="#+id/state_spinner"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_below="#+id/city_edit"
android:layout_margin="5dp"
android:layout_alignParentRight="true"
android:textSize="40dp" >
</Spinner>
Or you might try adding a background color:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinnerTarget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#00000000"
android:background="#FFFFFFFF"
android:textSize="40dp" />
The solution I came up with was to use android.R.layout.simple_dropdown_item for my spinner when an sdk less than 11 is detected, and when the sdk is greater than 11 I use my custom spinner. This seems to work ok. Not my favorite solution, but it does work.
Try this one ..
spnPlan = (Spinner) findViewById(R.id.set_spinner1);
ArrayAdapter<CharSequence> planAdapter = ArrayAdapter.createFromResource(
this, R.array.plan_size, android.R.layout.simple_spinner_item);
planAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnPlan.setAdapter(planAdapter);
spnPlan.setOnItemSelectedListener(new MyOnItemSelectedListener());
Related
I have a spinner with custom layout, in all android version except 5 it looks normal BUT just in android 5 the first item getting overlap.
version like 4.4, 4.2 the spinner looks normal.
here is a picture of what is happening:
the left is android 5 and right is android 4.4
i'm filling spinner with this:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.language_name, R.layout.lang_filter_base_layout);
adapter.setDropDownViewResource(R.layout.lang_filter_item_layout);
languageSpinner.setAdapter(adapter);
the lang_filter_item_layout :
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"
android:textColor="#color/medium_gray"
android:textSize="#dimen/language_spinner_text_size"/>
the lang_filter_item_layout:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center"
android:textColor="#color/medium_gray"
android:textSize="#dimen/language_spinner_text_size"
android:padding="#dimen/language_spinner_item_padding"
the spinner in my fragment:
<Spinner
android:id="#+id/language_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:spinnerMode="dropdown"
android:layout_centerVertical="true"
android:popupBackground="#color/light_gray"/>
any help would be appreciated.
So in the attached screen shot and the code sample you can see my custom spinner. As you can see my text is getting cut off no matter what I try to do. The nine patch image is set up correctly with the text padding on it too. I have right just about everything and am at a complete loss...
Custom spinner
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinner"
android:textColor="#555"
android:textSize="22sp"
android:textStyle="bold"
android:typeface="normal"
android:layout_width="wrap_content"
android:layout_height="40sp"
android:gravity="center_vertical|left"
android:singleLine="true" />
Implementing custom spinner
<Spinner
android:id="#+id/spinner_both20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/b_both20"
android:layout_alignTop="#+id/b_both20"
android:layout_marginLeft="4sp"
android:layout_marginRight="5sp"
android:layout_toRightOf="#+id/b_both20"
android:background="#drawable/buttons"
android:padding="20sp" />
Java
ArrayAdapter<CharSequence> aBoth = ArrayAdapter
.createFromResource(getActivity().getApplicationContext(),
R.array.d20both, R.layout.spinner_settings)
I'm super frustrated to be spending this many hours on something so simple. Any help would rock!
Padding will cut cut into your inner text.
I've made a custom spinner but the sizing isn't exactly what I want it to be. The spinner become far to large to get the spacing in the list that I need. I want to be able to size the rows of the spinner independently of the size of the spinner button. I want the spinner to be thin and then I want the section rows to be spaced generously. (See image at the bottom):
Currently the xml for the rows of the spinner is this:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="#+id/tableRow1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:padding="5dip">
<ImageView android:layout_width="32sp" android:src="#drawable/icon"
android:id="#+id/spinnerimage" android:layout_height="32sp" />
<TextView android:textSize="22sp" android:textStyle="bold" android:textColor="#000"
android:layout_width="fill_parent" android:id="#+id/category"
android:layout_height="fill_parent" android:paddingLeft="5sp" />
</TableRow>
</TableLayout>
I wanted to use a relative layout but the table layout gave me slightly better spacing. If I try to make the height it will cut off the text and icons in the rows. The spinner in my main.xml is:
<Spinner android:id="#+id/catspinner"
android:layout_marginLeft="25dip" android:layout_marginRight="25dip"
android:layout_width="fill_parent" android:layout_centerHorizontal="true"
android:layout_height="wrap_content" android:prompt="#string/prompt"
android:background="#drawable/yellow_btn"
android:layout_centerVertical="true" android:drawSelectorOnTop="true" />
I would like to have the spinner the sizing to be the same as the standard android spinner (on right.) Mine is currently reversed the spinner is to big and the rows spacing is too small.
Any ideas??
while setting adapter say adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
this should work...
Maybe this is quite late but I'll share this anyway because I came across a similar problem.
You need to use the Views "simple_spinner_item" for the Spinner itself and "simple_spinner_dropdown_item" for the dropdown.
Here's a code snippet:
Spinner spnCat = (Spinner) findViewById(R.id.idea_category);
Cursor c = myDBHelper.getCategories();
startManagingCursor(c);
if (c != null) {
// use the simple_spinner_item view and text1
SimpleCursorAdapter adapterCat = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item,
c,
new String[] {c.getColumnName(1)},
new int[] {android.R.id.text1});
spnCat.setAdapter(adapterCat);
// use the simple_spinner_dropdown_item
adapterCat.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item);
}
Hope that helps.
I can't fill a ListView layout with an array of strings. Here is the Activity:
ListView symptomList = (ListView) findViewById(R.id.ListView_Symptom);
String symptomsArray[] = new String[1024];
// Then I fill up symptomsArray
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, R.layout.menu_item, symptomsArray);
symptomList.setAdapter(adapt);
Here is menu_item:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:textSize="#dimen/menu_item_size"
android:text="test string"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:shadowRadius="5"
android:gravity="center"
android:shadowDy="3"
android:shadowDx="3" />
And here is symptom.xml -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_height="wrap_content"
android:id="#+id/ListView_Symptom"
android:layout_width="fill_parent"
android:divider="#drawable/divider"
android:listSelector="#drawable/textured"
android:layout_alignParentTop="true"></ListView>
</LinearLayout>
Does anyone have any idea what is wrong? Does my public class need to extend "ListActivity". I tried that and that didn't work.
Try stripping out some of the presentational bits from your TextView. For example, I don't think that you want android:layout_gravity="center" there. Also, try setting your ListView's android:layout_height="fill_parent".
Turns out Eclipse is so slow running on my 5 GB Dram MacPro that it eventually worked and displayed the array in the ListView, it just took a few minutes! Sorry about the confusion.
I am trying to modify the design of Spinner widget. I can change the background, but I can't find a way to change the arrow icon on the right side. Is there a way to do it?
Thanks!
The whole thing is a single 9 patch png image. I've modified the entire look of spinners before by replacing the images. See this page: http://androiddrawableexplorer.appspot.com/
Specifically look at btn_dropdown_normal.9, btn_dropdown_pressed.9, btn_dropdown_selected.9 and btn_dropdown_disabled.9
You just need to provide your own versions of those images.
Also, you can place your "spinner bar" layout in a FrameLayout, together with the real spinner but set to invisible:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="32dip"
>
<Spinner
android:id="#+id/theSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="32dip"
android:background="#drawable/my_background"
android:padding="6dip"
android:clickable="true"
android:onClick="spinnerBarReplacementClicked"
>
<ImageView
android:id="#+id/replacementSelectImg"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/my_drawable"
/>
<TextView
android:id="#+id/replacementSelectText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="4dip"
android:layout_toLeftOf="#id/replacementSelectImg"
android:textColor="#000000"
android:textSize="14sp"
android:ellipsize="marquee"
android:singleLine="true"
/>
</RelativeLayout>
</FrameLayout>
and pass the clicks from your layout to the real spinner
private Spinner mSpinner;
mSpinner = (Spinner) findViewById(R.id.theSpinner);
public void spinnerBarReplacementClicked(View pV){
mSpinner.performClick();
}