skip to Main Content

I set up a database in Backendless and started running it on Android Studio. The app is able to access the database and the connection is stable. But when I run the app, it only returns one result from the database. Is it possible to loop through all the items in the database? I built the app using this tutorial: https://www.youtube.com/watch?v=KeYC6gJyt-k&t=1524s&ab_channel=JohanJurrius Here is my code.

package com.mbass.examples;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.backendless.Backendless;
import com.backendless.IDataStore;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.persistence.DataQueryBuilder;

import java.util.List;
import java.util.Map;

public class MainActivity extends Activity {
    private TextView status;
    private TextView listtext;
    private Button updateButton;
    List<VIdeos> videos;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        Backendless.setUrl(Defaults.SERVER_URL);
        Backendless.initApp(getApplicationContext(), Defaults.APPLICATION_ID, Defaults.API_KEY);

        status = (TextView) findViewById(R.id.status);
        updateButton = (Button) findViewById(R.id.update_button);
        updateButton.setEnabled(false);
        final int[] textViews = {R.id.textView1, R.id.textView2, R.id.textView3};
        String whereClause = "name != 'Bill'";
        DataQueryBuilder queryBuilder = DataQueryBuilder.create();
        queryBuilder.setWhereClause(whereClause);
        queryBuilder.setPageSize(10).setOffset(0);
        queryBuilder.setSortBy("name");


        Backendless.Persistence.of(VIdeos.class).find(queryBuilder, new AsyncCallback<List<VIdeos>>() {
            @Override
            public void handleResponse(List<VIdeos> response) {
                for (int i = 0; i < response.size(); i++) {
                    Toast.makeText(MainActivity.this, "Name: " + response.get(i).getName() + "n" +
                            "ID: " + response.get(i).getCreated(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                Toast.makeText(MainActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
            }
        });
    }
}

                                    

2

Answers


  1. What happens when you comment out this line?

    queryBuilder.setWhereClause(whereClause);
    
    Login or Signup to reply.
  2. Your code sets the page size to 10 objects with the following line of code:
    queryBuilder.setPageSize(10).setOffset(0)

    The response is an array containing 10 objects. If you need more objects, change the page size. The maximum page size is 100

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search