IF fail, I need help

67 views
Skip to first unread message

JFK422

unread,
Mar 28, 2015, 9:55:30 AM3/28/15
to androi...@googlegroups.com
Hi Guys
I have a problem

This is supposed to animate a layout when a item on a first list is tabbed. Then it reads some data form the database.
Finally it should filter out some stuff which is in the databse and add it into a second list.
But going through the code gave me the bug that the marked if does not work.

It wold be niche if someone could help me solving that.

PS: Sorry for bad english.

//Variables
fdb = "";


function list_OnTouch(item )
{
    fdb = item;
    lst = [];
    last.SetList( lst );
    db.ExecuteSql( "select * from noten;", [], Draw ); <- my Database

    back=6;
}

function Draw( results )
{
    var len = results.rows.length;
    for(var i = 0; i < len; i++ )    
    {  
        var content = results.rows.item(i)
        if( content.data == fdb ){ <- This if doesn't work but why???
            last.AddItem( content.data_Name, content.data_Val );
        }
    }
}

madlyR

unread,
Mar 28, 2015, 11:28:35 AM3/28/15
to androi...@googlegroups.com
JFK,
change line:
 if( content.data == fdb ){
to:
 if( content.data_Name == fdb ){

In last_OnTouch( item )
item is a string from title last.AddItem( title, body, image ), so you should check content,data_Name.

You may add debug info (results in Debug tab):

function list_OnTouch(item )
{

  app
.Debug( item );
 
..



JFK422

unread,
Mar 29, 2015, 10:52:00 AM3/29/15
to androi...@googlegroups.com
First thanks fot th help madlyR.

I've tried it with debugging and some popups,
there was the data which i have expected.
So there must be some kind of a bug in the if.

Also here's the code of the database.
db = app.OpenDatabase( "Note" );    
db.ExecuteSql( "CREATE TABLE IF NOT EXISTS noten " +   
        "(id integer primary key, data text, data_Name text, data_Val integer)" );
           ^just the id in the list   ^              ^                          ^and this integer
                                            |               |If its a match then this string should be added to the second list
                                            | The string that should be compared with the touched item in the first list

What i've tested:

function Draw( results )
    var len = results.rows.length;   
    for(var i = 0; i < len; i++ )    
    {   
        var content = results.rows.item(i)
        var filter = content.data;
        app.ShowPopup( filter ); <- The text i expect
        app.ShowPopup( fdb ); <- The item I tabbed on the list is also there
        if( filter == fdb ){ <- I have checked they must be the same
            app.ShowPopup( "lol" ); <- Doesnt show up
            last.AddItem( content.data_Name, content.data_Val );
        }
    }
}

Reply all
Reply to author
Forward
0 new messages