spinner

create adapter to fill Spinner with objects [closed]

喜你入骨 提交于 2019-12-07 15:14:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have an Android application with a Spinner and want to fill it dynamically with my own objects. The objects do exist already as a List<T> . The objects are of type Category : public class Category implements Serializable { private Long id; private String name; // constructors // getter & setter // hashCode,

Populate Spinner from string array source, with a String ArrayAdapter

谁说我不能喝 提交于 2019-12-07 12:47:51
问题 I have created my application by populating spinners within my Java code. I am now trying to convert it to populating my Spinners from my strings.xml file. I have followed a few websites( example 1 and example 2 ), but have not been able to get my code to work. The main problem with those is that the ArrayAdapter's they use are of type <CharSequence> . Can I do this somehow using <String> ArrayAdapters? This is my array in my XML file : <string-array name="anti_pump_ap_mode_array"> <item>OFF<

Spinner in dialog - NullPointerException

二次信任 提交于 2019-12-07 11:40:45
问题 I want to show custom dialog with a spinner. Strangely enough, I get NullPointerException when I try to set the adapter of the spinner... Dialog dialog = new Dialog(this.getApplicationContext()); dialog.setContentView(R.layout.dialog_spinner); ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[] {"0","1","2"}); spin = (Spinner)dialog.findViewById(R.id.spinQ); //What am I doing wrong here? spin.setAdapter(spinnerAdapter);

How to set the selected item color in the spinner?

前提是你 提交于 2019-12-07 11:36:17
问题 <Spinner android:id="@+id/spinner1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1F" android:layout_alignTop="@+id/txtLabel1F" android:entries="@array/cat_array" android:prompt="@string/cat_promt" android:textColor="#ffffff" /> My Background is black and the item showing is with gray bg and black font color. But when it come to the selected it shows the font as black so it is not being seen. How do I change the color in it?

How to update the Drop-down Navigation title when user selects an option?

白昼怎懂夜的黑 提交于 2019-12-07 09:19:26
I have a Drop-down Navigation (Spinner) in my Action Bar. For creating the spinner, I used the code below, on my onCreate() method: //SPINNER SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.main_options, android.R.layout.simple_spinner_dropdown_item); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getActionBar().setListNavigationCallbacks(mSpinnerAdapter,this); main_options is a array in strings.xml resources, and has 3 options, which are shown on the Drop-down Navigation list (Spinner) when Activity is shown. Currently, the first option appears as

自定义可显示多行的 Spinner

旧巷老猫 提交于 2019-12-07 09:11:29
效果图如下: 为了增加按钮点击时的效果,此控件继承自 LinearLayout,LinearLayout 中添加一个模样类似于 Spniner 的 Button,在点击 Button 的时候显示数据。自定义变量如下: /** * Dialog 模式 */ public static final int MODE_DIALOG = 0; /** * dropdown 模式 */ public static final int MODE_DROPDOWN = 1; /** * 默认选择 dropdown 模式 */ private static final int MODE_THEME = -1; private SpinnerPopup mPopup;// 两种 Popup 模式实现的同一接口 private Button mSpinnerButton;// 默认Button private ListAdapter mAdapter; private int mTextColor;// 字体颜色 private int mSelectedItemPosition;// 选中的位置 初始化,根据资源文件设置显示数据的模式: /** * 初始化 * @param context * @param mode 显示数据的模式:下拉或者dialog */ private void init

save value of spinner selected item using shared preference

瘦欲@ 提交于 2019-12-07 09:05:41
问题 How can I save the current selected spinner value, such that when I reopen the application the saved value is automatically selected by default? My current code: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loginpage); final Spinner spinner = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.spinner_array, android.R.layout.simple_spinner_item); adapter

Can I force the dropdown view of a spinner to stay visible on orientation changes?

≯℡__Kan透↙ 提交于 2019-12-07 07:56:44
问题 I don't know if it's clear from the title what I asked, so here are some steps to reproduce (assuming you have a layout with a spinner): Tap on the spinner > dropdown list opens. Rotate the device from portrait to landscape (or vice-versa) > the list is closing. My problem is that I would like to keep the list opened after rotating the device. I know that this is usually possible if overriding onConfigurationChanged , but I have defined a different layout for landscape mode, so in my

Spinner with long text not working fine

我的梦境 提交于 2019-12-07 04:50:09
问题 I have some problems with the spinner. Depending of my dates, I must add to a TableRow a TextView with an EditText or a Spinner . My array that must be display in Spinner is a little long. I tested my code with an array with short texts, and it looks like this : Here the single problem is that spinner is not fill_parent . If I put my array to spinner it looks like this : In this case, the spinner doesn't look like a spinner and the EditText is not visible any more. When I choose the spinner,

Android Spinner not working on Samsung Devices with Android 5.0

梦想与她 提交于 2019-12-07 02:32:20
问题 I'm using a custom Spinner widget with the code below. Everything works fine on most devices except on Samsung's devices with Android 5.0. On click the Spinner should display a list of values but that doesn't happen. On emulators and others brands devices with Android 5.0 it works fine. Has anyone faced a similiar isse or have any idea of what might be happening? xml <?xml version="1.0" encoding="utf-8"?> <Spinner android:id="@+id/_combo_spinner" android:layout_width="0px" android:layout