aspose file tools*
The moose likes Android and the fly likes ListView duplicate everything Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "ListView duplicate everything" Watch "ListView duplicate everything" New topic
Author

ListView duplicate everything

ibrahim yener
Ranch Hand

Joined: Jul 22, 2013
Posts: 126

Hello All

i am building a SQLite application (Educational Purpose), i can retrieve data records from SQLite and display in ListActivity screen.
The problem is everything in te screen is duplicating. I am adding ScreenShot of emulator for idea.

I really appreciate if someone point my mistakes in following codes.

Regards



[2013-11-12 12_11_44-5554_WideScreen.png]



WinSystems my Google play account.
Ping Kong
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

The first thing to do is to check out what is in the database. When you run the query, Log each value that comes out. If they come out duplicated like that then you know the problem is you put the data in the DB multiple times. Otherwise you know it is in the display.


Steve
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

On the display side, I notice you use a class member variable to store the results of the query, but you never clear the List. Each time onCreate() is called, the query is made and the results will be added to the list. onCreate() could be called multiple times if you exit the application and come back in before Android killed it (which could be a while if the OS doesn't need the memory) or if you go to another Activity and then back to this one using an intent.

I would think there is no need for the variable that holds the results to be a class member. I would make it a method-local variable unless there was a driving need to use the data elsewhere. And if the need existed, I would make sure to clear the List before running the query again.
ibrahim yener
Ranch Hand

Joined: Jul 22, 2013
Posts: 126

Dear Steve
I have checked Database output as you suggested and seems query is fine and properly retrieving from SQLite.

Also i took queryResult array into runQuery() but nothing changed.

Thank you for your reply.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

Can you show the new code, and on your side clean the project, rebuild it, and relaunch? Do something (check logs, or whatever) to know that you are running the correct version of the application on the phone/emulator
ibrahim yener
Ranch Hand

Joined: Jul 22, 2013
Posts: 126

Hello again
I have cleaned up code and changed it as below

I have tested code Emulator Android2.3 and Android 4.3 also tested actual SonyEricsson Xperia Android 2.3.4 result is all same.

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

I don't think the recordID is the right thing to print to determine duplicates in the DB - no line in the DB will have duplicate IDs. Log out the meaningful data (all the other columns).
ibrahim yener
Ranch Hand

Joined: Jul 22, 2013
Posts: 126

Dear Steve

Thanks for help, i really appreciate for that.

So, i changed id to another data (memo) db records retrieve without mistake (was checked at same time on SQLite Database Manager)
I thought, maybe codes are fine and i am mistaking by layout.xml

FYI, I am writing layout.xml file as well.

Regards

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

So maybe I am confused about what the problem is. You are displaying this data:
2013/01/01 - 2099/12/31 baska bi deneme
2013/01/01 - null/null/null deneme
2013/01/01 - null/null/null deneme
2013/01/01 - null/null/null deneme
2013/01/01 - null/null/null baska bi deneme

Each of these elements is displayed exactly once on your screen, 3 of them look like duplicates. Is your problem the values that are displayed or the labels, since each one is displayed as:
Reminder / Task Manager
2013/01/01 - 2099/12/31
baska bi deneme

I now think the problem is the labels. It looks like you expect the ListView to fill in the list inside the last TextView with the id textView2, under the LinearLayout id listWrapper. That isn't how it works. The ListActivity has its own layout consisting of just a ListView. The layout you give it is the layout for the elements that go in the list, and the id of the view you give it is where the text actually goes in that layout. So for every item in your list, the whole R.layout.task_list is expanded and added to the list.

I think what you want to do is replace the default layout for the ListActivity (see the API for how) and have a second layout for the contents of the list (which may consist just of a single TextView to hold the data if you want).
ibrahim yener
Ranch Hand

Joined: Jul 22, 2013
Posts: 126

Dear Steve
Those records are not duplicate. I have just pressed Save button multiple times.

Anyway, I removed title of app for now but i need to learn how to do as soon as possible.

I am reading url which you provided.

Thank you for help, i really appreciate.

Regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ListView duplicate everything