How to hide first item in an android spinner dropdown? [duplicate] - android

This question already has answers here:
How to make an Android Spinner with initial text "Select One"?
(36 answers)
Is it possibile to set hint Spinner in Android [duplicate]
(3 answers)
Closed 6 years ago.
I'm using adapter.add for adding a title in my spinner, but how to hide first item in an android spinner dropdown?
Here is My Code:
var spinner1 = FindViewById<Spinner>(Resource.Id.spinner1);
var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerItem);
spinner1.Adapter = adapter;
adapter.Add("Select one...");
adapter.Add("Name");
adapter.Add("Mobile");
adapter.Add("Age");
See images below:

Related

How to remove all items in table object [duplicate]

This question already has answers here:
Empty an array in Java / processing
(8 answers)
clear method in an array
(6 answers)
The best way to empty array in java
(5 answers)
How to remove all elements in String array in java? [duplicate]
(6 answers)
Closed 5 years ago.
I have a table object 'list_animal':
Animal[] list_animal = new Animal[3];
list_animal[0] = new Animal(...);
list_animal[1] = new Animal(...);
list_animal[2] = new Animal(...);
I want reomve all data in 'list_animal'.
Your question is a bit vague. If I understand correctly, you can do this:
list_animal = new Animal[3];
Or you can assign NULL to each element.
From here How to remove all elements in String array in java?
You can do this
Arrays.fill( list_animal , null );

Set the default Text into spinner programmatically [duplicate]

This question already has answers here:
How to make an Android Spinner with initial text "Select One"?
(36 answers)
Closed 9 years ago.
I have a spinner like this:
Spinner spinner = new Spinner(context);
spinner.setPadding(0, 10, 10, 0);
ArrayAdapter<ItemValue> aa = new ArrayAdapter<ItemValue>(context,
android.R.layout.simple_spinner_item,elemItemSet);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(aa);
Now I need a add a default/initial text programmatically (without using xml) & without adding into list 'elemItemSet'.
Is it possible?
To show defualt value(Select) at spinner,you have to add "Select" text into your array list at O index. And apply condition like "When the value of spinner is 'select' then show message to user like 'Select any value'".
I hope it will help you.
Thnaks

Android TextView to displays a number to two decimal places only through XML [duplicate]

This question already has answers here:
Round a double to 2 decimal places [duplicate]
(13 answers)
Closed 9 years ago.
I am populating a ListView using TextView as a row through SimpleCursorAdapter.The numbers in the TextView are displayed as say 8 or 2.6786 etc.I want them to be displayed as 8.00 or 2.67 etc.Can it be done through XML(like input Type method etc).Please suggest a wayout.
The question is bit different as under:
The codes are:
// THE DESIRED COLUMNS TO BE BOUND
columns = new String[] { slStock.KEY_SCRIPT, getColumnName(2),c.getColumnName(3)};
// THE XML DEFINED VIEWS FOR EACH FIELD TO BE BOUND TO
to = new int[] { R.id.tvstockscrpt, R.id.tvqty ,R.id.tvstockrate};
// CREATE ADAPTER WITH CURSOR POINTING TO DESIRED DATA
SimpleCursorAdapter cursAdapter = new SimpleCursorAdapter(this,R.layout.rowstock, c,columns, to);
lvstockdisplay.setAdapter(cursAdapter);
Here you will notice that the cursor c fetches data (from database query in background) and populates it in the ListView directly.The question is how can I format the cursor data for say the TextView whose id is(R.id.tvstockrate) and which is populated by c.getColumnNames(3).At which point in the codes the format statement can be inserted.
What about formatting the text when you set it?
yourTextView.setText(String.format("%.2f", value));
This could be your solution
yourTextView.setText(String.format("%.2f", value));

Shuffling an Adapter [duplicate]

This question already has answers here:
Random shuffling of an array
(31 answers)
Closed 9 years ago.
I am using an Adapter:
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1);
and I want to shuffle the contents of it, however I discovered that Collections.shuffle(adapter); does not work. Is there another method to do this? While keeping the format of adapter i.e. not changing it to a List
Of course Collections.shuffle(adapter) doesn't work..shuffle takes a java.util.List... The Java Collections API knows nothing about the Android API...
You need to shuffle the underlying List and then then tell the adapter that the data has changed..something like:
Collections.shuffle(myList);
adapter.notifyDataSetChanged();

On tab key request focus on spinner-Android [duplicate]

This question already has answers here:
Spinner does not get focus
(4 answers)
Closed 10 years ago.
I have a registration form where flow goes as EditText1->EditText2->Spinner->Editext3 ,but on tab press the of EditText2 control is transferred to editText3 and not Spinner How can i do that in android??Can anyone help plz
Use this before your Oncreate()
Spinner spin = (Spinner) findViewById(R.id.spinner1);
spin.setFocusable(true);
spin.setFocusableInTouchMode(true);
spin.requestFocus();

Categories

Resources