How to use ContainerList in lwuit 1.5? - list

My list having variable length list items. ContainerList supports variable length list items. When I explored it on internet, I can't find any samples for ContainerList. Give me a sample piece of code to work on ContainerList.

LWUIT demo contains a ContainerList sample in the Scroll demo.
There is also an explanation in our blog http://codenameone.blogspot.com/
Generally ContainerList is a drop-in replacement for list, just replace the usage of List with ContainerList and it should work pretty seamlessly (albeit slower).

Try this:
Vector variableLengthVector = new Vector();
variableLengthVector.clear();
for(int i=0;i< variableLengthStringArray.length;i++)
{
variableLengthVector.add(variableLengthStringArray[i]);
}
List myListToBeDisplaye = new List(variableLengthVector);
variableLengthStringArray--> It contains the items that you wish to show in your list.
So whenever you want to display a list , just populate a vector and initialize your list with that vector. Ensure, that you clear that vector or re initialize the vector before populating it.
Now, simply paste your list on a form or wherever you wish to display it..
Ok, you can find stuff about containerList here:
http://lwuit.java.net/nonav/javadocs/com/sun/lwuit/list/ContainerList.html
You can use a container list like this:
ContainerList abc = new ContainerList(new DefaultListModel(variableLengthVector));

Related

How to delete duplicate constructed objects in a list while preserving order and returning a List in dart?

I have a list of constructed objects called RecentCard which is basically an object with user id, pic, and name. I have created a list arranged in order of most recent interaction based on timestamp. However i need to get rid of the second occurence and onwards of any duplicated object. I am comparing just the ids since users may have the same name or photo, and i cannot remove duplicates from a simple list of uids because then i could lose the order of corresponding photos and names.
For example the list would look something like this :
List<RecentCard> recentCards= [RecentCard(uid:as721dn18j2,name:mike,photourl:https://sadadasd1d1),RecentCard(.....]
I have searched for solutions but all of them are dealing with like primitive types like simple lists of strings and the solutions didn't work for me. For example this post: How to delete duplicates in a dart List? list.distinct()? Read below
The first answer's link is no longer available, the next answer with sets is something i tried but it simply doesnt work i have no idea why maybe because its not a primitive type. The next answer with the queries package didn't work because i was using the list to build a listview.builder and so when i called list.length it said i couldnt call that on an iterable or something. The final solution wouldn't work because it said String is not a subtype of RecentCard.
I tried using two forloops with the second just comparing first value to the next couple but that doesnt work because if a duplicate is found, the object is removed and the length is messed up so some elements get skipped.
Any ideas? I feel like its very simple but im not sure how to do it.
You have to use Set to store seen cards and then filter away those ones that are already in the set.
final seenCards = Set<String>();
final uniqueCards = recentCards.where((card) => seenCards.add(card.uid)).toList();

Python pptx: how to find and delete the empty or unpopulated placeholders

I have created a presentation using python-pptx. However, some slides have the empty placeholders with default text click to add title/text that looks like the one below.
So basically, there are non-empty placeholder with text Some texts here and other two are empty placeholders. How can I find and delete them? Also, there are same empty placeholders for images. How can I find them as well. Thanks
Finding them is fairly easy; something roughly like this should do the trick:
for placeholder in slide.shapes.placeholders:
if placeholder.has_text_frame and placeholder.text_frame.text == "":
print("found one %s" % placeholder)
Deleting it is harder, because there is no direct API support for deleting shapes. However, in this simple case of text placeholders, this should work:
sp = placeholder._sp
sp.getparent().remove(sp)
The ._sp attribute is the lxml etree._Element object representing the actual shape XML element (a placeholder <p:sp> element in this case). .getparent() and .remove() are methods on etree._Element and calling these manipulates the underlying XML directly. This can be dangerous, like if you tried this with a chart shape you'd probably get a repair error when you tried to load the presentation, but in this case it's safe enough.

exam C++ save name attribute of list

During my C++ exam I found I had some difficulties with what is probably supposed to be something relatively simple. I think I am overlooking something on my problem. For the sake of not getting in trouble for posting part of an exam online, I will make a very simple representation of the part I had troubles with.
What was expected was to make a class myClass in which i could add items item. Then i was supposed to be able to make lists of some items i wanted in that list. The amount of items able to be in the list should be infinite. Each list should have a certain (unique) name. I am also told not to make a new class for the lists and to choose the right container myself.
myClass::myClass(){
itemlist= {};
lists= {};
}
void myClass::addItem(Item &item){
itemlist.emplace_back(item);
}
void myClass::makeList(string listname){
vector <Item> list = {};
// list .name = listname
lists.emplace_back(list);
}
void myClass::addItemToList(string listName, Item &item){
for (int i=0; i<lists.size; i++){
if lists[i].name == listName {
lists.emplace_back(item);
return;
}
}
}
I don't know how to link a name to a list without creating a new class for the lists. I thought about storing another list containing the names of the lists and using that, but it seemed wrong to do so, as they aren't actually linked then. Tried to look up if there is a way to make a list variable listname from the string listname parameter, but apparently that's not possible.
As for the containers, I chose a vector as they can store an "infinite" amount of data in it. I use the itemlist to store all items ever added to myClass, and lists to store all the lists ever created.
In what way is it possible to store a name for each list and for it to be linked?
I think the simplest way to name lists is to use std::unordered_map http://en.cppreference.com/w/cpp/container/unordered_map
Then you'll be able to use your lists like this:
lists["first_list"].push_back(...);
lists["another_list"].size();
lists["create_new_list"] = {};
Maybe what you are looking for "link a name to a list" is a std::map
Something like
std::map<std::string, std::vector<Item>>

Working with lists and adding elements

in C# if I declare a new list say, myList, can I add items to that list later at a specific index location like this, myList[2] = 42. And can I then write over that index location again without first deleting it by doing myList[2] = 28?
No, it will give you ArgumentOutOfRangeException
It sounds like an array would be a better choice.

Add to list within document MongoDB

I have a database where I store player names that belong to people who have certain items.
The items have and IDs, and subIDs.
The way I am currently storing everything is:
Each ID has its own collection
Within the collection there is a document for each subID.
The document for each subID is layed out like so:
{
"itemID":itemID,
"playerNames":[playerName1, playerName2, playerName3]
}
I need to be able to add to the list of playerNames quickly and efficiently.
Thank you!
If I understood your question correctly, you need to add items to the "playerNames" array. You can use one of the following operators:
If the player names array will have unique elements in it, use $addToSet
Otherwise, use $push