• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Listview question

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I am currently trying to create a minor android app. Hoping to learn from it while doing it. Now I stumbled upon the following problem: I wan't to make a new activity. Like the one in the third codeblock. However, this activity should show a listview with 3 listview-buttons, one for minimal, medium and maximum.

To clarify: the user will get a listview (this one works already) than select one button from this listview and he goes to the next activity with another Listview which has the 3 problematic buttons filled with the variables maximum, medium and minimal.

Problem is, I do not now how to get this done. I am still learning and I do not see how I can extract these 3 parameters from the items in the List<FoodTimes> and showcase ehm. Mostly because the toString method in the FoodTimes class returns a name. How the heck do I make it so that this class returns OR the name OR minimal, medium & maximum (without me getting a list of hashcodes instead of Strings) ?

I have created a class which provides and arraylist:



a class which defines the items in the list:



And a class which shows the first parameter of the FoodTimes objects in a listview:



And lastly my attempt: --> which does not work because I do not see how I can get the right data in the String array (and I doubt if I am even in the right direction. I hope you understand what I am trying to ask as I feel my head is wuzzling and things aren't super clear atm:P Thanks in advance for any help!

 
Ranch Hand
Posts: 42
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dirk Lucas wrote:Hello!

I am currently trying to create a minor android app. Hoping to learn from it while doing it. Now I stumbled upon the following problem: I wan't to make a new activity. Like the one in the third codeblock. However, this activity should show a listview with 3 listview-buttons, one for minimal, medium and maximum.

To clarify: the user will get a listview (this one works already) than select one button from this listview and he goes to the next activity with another Listview which has the 3 problematic buttons filled with the variables maximum, medium and minimal.

Problem is, I do not now how to get this done. I am still learning and I do not see how I can extract these 3 parameters from the items in the List<FoodTimes> and showcase ehm. Mostly because the toString method in the FoodTimes class returns a name. How the heck do I make it so that this class returns OR the name OR minimal, medium & maximum (without me getting a list of hashcodes instead of Strings) ?

I have created a class which provides and arraylist:



a class which defines the items in the list:



And a class which shows the first parameter of the FoodTimes objects in a listview:



And lastly my attempt: --> which does not work because I do not see how I can get the right data in the String array (and I doubt if I am even in the right direction. I hope you understand what I am trying to ask as I feel my head is wuzzling and things aren't super clear atm:P Thanks in advance for any help!



I don't 100% know what it is you're trying to do, but I understand that you're trying to allow the user to press one button from a listview (Which you already have working), which then takes them to another listview with 3 buttons which have written on them the 3 variables (maximum, medium and minimal)?

If I'm correct, then all you need to do to pass the variables to the new activity which displays the 3 buttons is use an intent.

Just do something like this:



then in your activity which has the three buttons you need to call getIntent() to obtain the variables.

so something like this



and just do the same for the other variables too.

Make sure you call getIntent() within the onCreate method. You can declare the variables as instance variables, but when you want to assign the variables using getIntent() make sure you do that within the onCreate method.

Once you have the variables you just need to add the code to make the buttons display them.

I'm not sure whether I answered your question or not but I hope this helped lol.
 
Dirk Lucas
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He! THanks for your answer. I will try and see if it works. Thing is, the minimal, medium and maximum vars relate to the last 3 numbers in the FoodTimes class:

data.add(new FoodTimes("Asparagus","5","8","12")); <--Those 3!

BUt I ll try to use the intents and ll see what happens. I ll report back!;)
 
reply
    Bookmark Topic Watch Topic
  • New Topic