This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

ListView empty  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to display the contents of a ListView I created but I only watch a white screen. The idea is to retrieve data of a database and put then in an ArrayList in order to display them. The ArrayList is of type Lugar that is a class.

Here is the code:



The code of class Lugar:



When I run the app there are no errors. I only watch a white screen. It seems ListView is empty and I don't know why.

How can I display data? I have data in the database.

Thanks.
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a couple of Toasts that get called when you populate the list, do they get displayed? If not, then you have to figure out why your cursor is empty (on a related note, you shouldn't do this: while(cl.isLast() == false). you should do this instead: while(!cl.isLast()). When comparing the return statement of a method it isn't a big deal, but when you do == true or == false using variables there is a critical mistake you can make. So it is best to avoid that habit altogether).

You show the code for Lugar, but not LugarAdapter. Does it properly inform the ListView it is attached to that there are values in the list?

What is your layout like? Does the ListView have a non-zero height? How about the views used to display the items in the list? Are they sized properly to show content?
 
Alex Munozz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Toasts are for checking if the values are correct. And the toast that I don't watch anything on the screen is this one:



What I only see is [].

The code for the ListAdapter is:



The layouts:

ListView layout:



Items Layout:



There are no errors. The cursor has data. The Lugar class I think it's empty.

How can I watch data in the cursor?

Thanks.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Alex Munozz wrote:Toasts are for checking if the values are correct. And the toast that I don't watch anything on the screen is this one:



What I only see is [].


So lugrs is empty. You also have Toast inside the while loop. Do they show up at all? If they don't then one of the following is true:
1. The cursor cl is null
2. cl has zero elements
3. There is only one row in the cursor (the first row is the last row. Your while loop is designed never to look at the last row.)
 
Alex Munozz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer. The problem is fixed. The issue was the loop:



I changed cl.isLast() for cl.isAfterLast() and I also put the creation of the object Lugar inside the loop.



And finally I can watch data from the cursor.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!