Android Display a random Item from List without showing the ListView - android-listview

I am practicing on this project called GetTours i got from github, now
I want to display random Item from the ListView without seeing the ListView. not only show random item from ListView, but also print the details of the items, the item contains Name, address and lat long value for the map marker.
is that even possible?
or maybe, Teach me how to create a list that contains a name, address and lat long value and how to display it. I am also planning of randomizing it every time i shake the device. I had an app that do shake an random with a single data array, now I want to randomize a place with Name, address and a Map marker in the said location per shake. please help!

A ListView is not needed here, save your items in a List :
ArrayList<Item> items = new ArrayList<Item>;
items.add(item1);
items.add(item2);
//...
Then select a random number with the maximum as the length of your list :
final int random = Random.nextInt(items.size());
And then, do what you need to do with the data :
Item randomItem = items.get(random);
nameTextView.setText(randomItem.getName());
priceTextView.setText("" + randomItem.getPrice());
//...

Related

Flutter: How can I keep my last last ..shuffle order in a new state?

Is there a way to keep an aspect of the page from updating when the State updates? Or to keep an instance of the ..shuffle so that I can re-use that shuffle order in the new state?
I have a GridView that fills up with items from a Map. These items are shuffled first to make them come in a different order each time people open that page.
Once they click on one of the items in the GridView I want to update the State so that I can change parts of the page...but I don't want to re-shuffle the map.
Is there any way to do this?
The Map and shuffle part of the code is like this:
final Map choices = {
'apple': selectSuccess,
'orange': selectFailure,
'cherry': selectFailure,
'banana': selectFailure,
};
choices.forEach((k, v) => choiceSet.add(SelectCardActivity(k, v)));
choiceSet..shuffle();

Is it possible to convert a string to the name of a list?

Before we come to the actual question, I'll need you to understand my App.
I have a function add() which feeds integers based on the user's input into a list. This list of integers is fed into a function avg() which calculates the average of all the integers inside of the list.
This list however, is bound to a widget which can be added infinite. But before a title for that widget must also be provided by the user.
Imagine it like that: You click on a floatingActionButton and a TextField opens. In that TextField you type in a title. After you submit the title a Box is crated with that title.
Inside this Box you have the possibility to click a Button which opens a new TextField. In that textField you type in an integer between 0-15 which then is added to the list bound to the widget.
That's why I need a new list of integers to be created, whenever I create a the users creates a new Widget.
That's why I was wondering if there is a way to just take the String of the title (lets say 'my awesome title') and use that to define a new list with that string (my thoughts in code are below).
Something like this:
String title = 'title';
List<int> 'title' = [];
Everything I found regarding this topic, didn't really covered the answer I was looking for. So please excuse me if this question was asked in a similar way before. I probably didn't understood it, hopefully you can help me out better. :)
If it is not possible to convert a String to a list name, I would love to hear about a different technique which would solve the problem explained.
If I understood you correctly You want to save the value as a identifier/variable name and use that for fetching other values? like list of integers.
In that case thing which might suit your case would be Map or key/value pairs.
Lets say you got a String from server or any other way.
String title = await getStringFromServer();
List<int> data = await getIntegersfromSomewhere(title);
Now you might want the map to come in action. you can save these values in map.
final Map<String,List<int>> _map = Map();
map[title] = data;
Now your map will contain whatever string you got from the server or from anywhere. and corresponding list of integers.

How to make a List that contains another list, in flutter

I was trying to make an app in flutter, I now have an app that adds a new element into a list upon pressing a FAB. Kindly let me know how can I map another ListViewBuilder to each element. I am not sure if I am being clear enough, but I am trying to be clearer. I want an app that lets you create lists inside of lists, in flutter. So for each List element, there lies a corresponding list in which the contents of the list can be added. I am a beginner, and I am struggling to figure it out. plzzz, help me out..thanks in advance...
To create a list in a list you can use:
List<List<int>> numbers = new List<List<int>>();
And then you can add a new list to this by doing:
numbers.add([0,1,2]);
This adds the list [0,1,2] to the list called numbers.
From here you can access an element in this case the second element in the first list:
x = numbers[0][1]

How do I add new list tile in order in Flutter? When I add new one it is added in random order

[Numbers should go 1,2,3 not like this][1]
i don't know how your code look like but if you add a new item it will be at the top and the first item will be at bottom. the list doesn't care about the items value if its 1 or 2.
If you want them in order use sort()
https://api.dartlang.org/stable/2.6.0/dart-core/List/sort.html

How can I search an Android ListView using hidden keywords?

I have a ListView with a list of rooms.
Some of the rooms in the list are Students' Activity Center, Classroom 101, and Classroom 102.
I also have an EditText which allows the user to search a room in the list.
However, I also want to add additional keywords which would not appear on the list but are searchable. For example, if the user searches for "SAC", the Students' Activity Center will be shown in the ListView.
Right now, the user could only search what is visible in the ListView.
You can use 2 override methods setTag(Object tag) and setTag (int key, Object tag) methods. Link at View setTag. Afterwards you call getTag to get the keywords, as you put it. Sample code:
String itemName = (String) myButton.getTag();
The idea of using tags is not new and has been used in various different libraries and frameworks.