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();
Related
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:
This question already has answers here:
WITH statement in Java
(8 answers)
Closed 8 years ago.
I am new to android and I've been trying to create a ListView example application, in which I've added items to Arraylist....
list.add("Item1");
list.add("Item2");
list.add("Item3");
.......
Is there any way in android to avoid typing "List" every Time....?
I know there is something ,But I couldn't find out what the keyword is..
in VB I could write
with list
.add("Item1");
.add("Item2");
Thanks in adavance
Actually, there isn't.. What you can do is use Arrays.asList(...) which you can pass any number of arguments to and you'll get a list with these items back
No, there's no Java equivalent of the Visual Basic with statement.
Check this question.
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));
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
ListView issue when displaying strings
I have the following code
List<Result> results = response.results;
i need the the values in "results" to be displayed in a listview. what should i write within for (Result result : results){}
You've asked a general question so the best I can do is give you a general answer. You don't use for(Results result: results){} You need to use an ArrayAdapter. For a tutorial on how to do so, please see this documentation.
i need to display four names continues in listview
for example
aravind
bose
guru
moorthy
aravind
bose
guru
moorthy
the set of values to be displayed in listview for "n" number of times
if i have mension 10times.the four names should be display for 10 times in listview.help me
for this you need to pass "n" as a parameter while calling your custom adapter.
Since its your custom adapter create your arrayList in the adapter to be used for the list view using the parameters of ArrayList(data to be displayed) and the "n". Using these create another arrayList which is used to display the listView data..
the call would be somewhat like this:
listAdapter = new CustomListAdapter(this, R.layout.list_view,
countryStringList, n);