#How to set and retrieve a class object in a ListView?

22 messages · Page 1 of 1 (latest)

gloomy summit
#

Hi,
I'm coding a project that has a class that is called Course, and I wanted to implement a way for a user in my application to search for courses. To do this, I've set up the retrieval from a database for courses. However, I'm currently stuck in figuring out how to display my objects into a ListView and then retrieving the object once a user selects one and clicks a button.

From what I've googled online, theres only solutions for displaying an object inside a list which doesn't solve the latter of my problem, and utilising an ArrayAdaptor to convert the objects into something recognisable for a list. However, the second solution I couldn't figure out how to extend the ArrayAdapter, and all the online guides seemed to be tailored for Android development rather than just a desktop application.

So, are there any simpler solutions to setting and retrieving a class object in a listview? And if the ArrayAdapter is my only solution, could someone help explain how it works, as I'm currently lost with the guides.

lyric gullBOT
#

This post has been reserved for your question.

Hey @gloomy summit! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

stiff parrot
#

Are you sure you are talking about JavaFX? AFAIK there is not ListAdapter necessary for listView...

gloomy summit
#

and the issue is I want to load an array of custom objects

#

into a list

#

and let a user select an option

#

and then retrieve the object from that selection

stiff parrot
gloomy summit
#

but im not sure how to go about doing that

gloomy summit
stiff parrot
#

sure

#

there is a "selectionModel" method on the ListView instance where you can add a listener to selectionChange

#

Also this "selectionModel" have a property of "selectedItem"

gloomy summit
stiff parrot
#

yes

gloomy summit
#

hm

#

ok, now its clearer

#

thanks mate

lyric gullBOT
# gloomy summit thanks mate

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.