/ Seriously / How to get information from a database table for android. For example, there is a “name” field, how to get its data. Method getname () to string returns null.
Could you please post the code you use to retrieve the data and a screenshot which shows your table schema in Backendless console?
Regards,
Mark
[reply user_id=1][h4]Mark Piller wrote:[/h4]Could you please post the code you use to retrieve the data and a screenshot which shows your table schema in Backendless console?
Regards,
Mark[/reply][reply user_id=1]I can not find enough information to understand how to retrieve data from the database to a string on the android.[/reply]
Suppose you have table called Person which a column named “name”. To retrieve data from that table you do this:
- Declare class Person:
public class Person
{
private String name;
public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
}
- Then use this code to retrieve your Person objects:
Backendless.initApp( YOUR_APP_ID, YOUR_ANDROID_SECRET_KEY, "v1" );
AsyncCallback<BackendlessCollection<Person>> callback = new AsyncCallback<BackendlessCollection<Person>>()
{
@Override
public void handleResponse( BackendlessCollection<Person> response )
{
}
@Override
public void handleFault( BackendlessFault fault )
{
}
};
Backendless.Persistence.of( Person.class ).find( callback );
the “response” argument in the callback (handleResponse method) will have the objects with data.
Make sense?
Yeah, I did, but how to get a string of “response”?
Each instance of the Person class in the resulting collection will contain string property which you can obtain using the getName() method.
HandleResponse should include getName (), or both, please append your code.
See the implementation of the handleResponse method - it calls getName() from the Person class:
AsyncCallback<BackendlessCollection<Person>> callback = new AsyncCallback<BackendlessCollection<Person>>()
{
@Override
public void handleResponse( BackendlessCollection<Person> response )
{
List<Person> firstPage = response.getCurrentPage();
for( int i = 0; i < firstPage.size(); i++ )
System.out.println( "name - " + firstPage.get( i ).getName() );
}
@Override
public void handleFault( BackendlessFault fault )
{
}
};
Backendless.Persistence.of( Person.class ).find( callback );