spinner

Spinner in dialog - NullPointerException

白昼怎懂夜的黑 提交于 2019-12-05 18:05:32
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); dialog.setTitle("Questions"); dialog.show(); The xml layout code: <?xml version="1.0" encoding="utf-8"?>

save value of spinner selected item using shared preference

拥有回忆 提交于 2019-12-05 16:19:15
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.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);

Show spinner in AlertDialog

拜拜、爱过 提交于 2019-12-05 15:28:13
I want to show a spinner in my alertDialog. I have the following code but it just give me a black screen. Logcat doesn't say any errors. MyActivity.java AlertDialog.Builder builder; AlertDialog alertDialog; Context mContext = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.spinner,null); String array_spinner[]; array_spinner=new String[5]; array_spinner[0]="US"; array_spinner[1]="Japan"; array_spinner[2]="China"; array_spinner[3]="India"; array_spinner[4]="Vietnam"; Spinner s =

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

人盡茶涼 提交于 2019-12-05 15:26:18
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 onConfigurationChanged method I have to call setContentView and set the adapter for the landscape spinner,

Dynamically setSelection of spinner, do not trigger OnItemSelectedListener

一笑奈何 提交于 2019-12-05 13:54:11
I have a activity that have many cascaded spinner and after select first one, second spinner initialize and fill data and after select item from second, third spinner initialize and fill data and so on. for each spinner I create them like this and it is iterative: public ArrayList<MaterialSpinner> spinnerlist = new ArrayList<>(); public void createView(){ final MaterialSpinner spinner = new MaterialSpinner(context); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){//...after select item next spinner creates with calling createView() iteratively} loadSpinnerData(); //

How can I manage the height of android spinner items?

空扰寡人 提交于 2019-12-05 13:27:04
问题 I have an android spinner that's populated by a list of strings using an ArrayAdapter and it operates fine, however because of the way the spinner is displayed I'm running into a display height problem with the list items. At first glance it would seem that the ArrayAdapter can use a single layout for displaying options which leads to the problem I'm having. When displaying the current item in the spinner (when the user is not selecting a new item from the list) the spinner pads the text so

How to set the selected item color in the spinner?

依然范特西╮ 提交于 2019-12-05 13:04:23
<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? JanBo You need to create a custom spinner layout to achieve what you want. check out these questions,

Spinner with long text not working fine

雨燕双飞 提交于 2019-12-05 09:40:06
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, it appears this view : Here I need to display all the text of the array. This is my code : TableRow

Android - set focus on EditText after Spinner selection

依然范特西╮ 提交于 2019-12-05 07:38:14
I have the following items displayed on the screen: EditText Forename Spinner gender selection (Male | Female) EditText Email When the application is first launched, I want the focus to be set on the Forename EditText. Then after "Male" or "Female" has been selected in the Spinner, I want the focus to be set on the Email EditText that is located below the spinner. I have used setOnItemSelectedListener to set the requestFocus on the email EditText, but the problem is that it automatically sets the focus on this EditText whenever I launch the application. This happens because by default the

Finding Fragment View on Activity. Android findFragmentByTag(String tag) returns null

。_饼干妹妹 提交于 2019-12-05 07:28:08
问题 I'm trying to get a Spinner View from an added Fragment to my activity but it seems that I cannot get the fragment nor the view. I have an Activity which adds a Fragment to it's LinearLayout , the fragment's layout is based on the 'extra' that comes from the intent of the Activity. Everything is displayed correctly and I can see all the views of the fragment but for some reason when I call findFragmentByTag(String tag) it returns null and thus I cannot call getView(). Here is how I am adding