• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How should I code this?

Nielsns

Lurker
I want to implement this “Block” so that it reflects information from a database.

When the user scrolls down it must repeat, so that the data per “Person” in the database can be reflected onto one single block.


How can I make it that the block repeats itself?
- If you have any resrouces for me to read on this topic please link them below. I am NOT asking for you to write my code. I am just asking for tips on how to do this the most efficient way.
- Can I group the design of this "block" into a block so that when there are more records that it will take this block and put the data on the "block".
 

Attachments

  • Panel X W-O Social Media Buttons – 5.png
    Panel X W-O Social Media Buttons – 5.png
    44 KB · Views: 67
Last edited:
I'd create a timer that repeats every second and polls the database for changes. This is chatty as heck but hey data being selected is what a database does best. Google android timer repeat and external database. You may have to use PHP to help poll the database. I haven't worked with Android databases for a while. From what I've heard and yet to read is that There is a new way to poll an external database in the latest SDK. a few years ago I would use volley to execute a PHP script that would then query the database and echo back the data as a JSON object.
 
That's the way I'm doing it right now - I use volley to ping the database URL every 10 seconds, and update the local SQLite DB, then trigger an update of the list.

For the repeating action, try postDelayed:

Code:
// class vars
private Handler mHandler = new Handler();

// function
private void loadDB() {
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            loadDB();
        }
    }, 10000); // milliseconds until run
}

The problem I'm currently having is that this continues even after I move to another activity - I don't yet know the solution to that, was working on it while reading this.
 
Timers are next to impossible to shut off I create a setter and a getter with the string 'lock_this_code' in my global class file then wrap the code I want to shut off with an if statement.
 
Actually, I managed to find a way to do that, too, not long after my first reply:

Code:
@Override
public void onDestroy() {
    mHandler.removeCallbacksAndMessages(null);
    super.onDestroy();
}
 
Back
Top Bottom