Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:29:51+00:00 2026-05-28T14:29:51+00:00

I’ve been using this for a while, and I’m not sure if I found

  • 0

I’ve been using this for a while, and I’m not sure if I found this technique in an example or just tried a bunch of things until it finally worked. My question is how does this line of code,

new ObjectInterfaceHandler(position, o, v);

actually make it to where this view Listens for the call backs from the ListReadyObject.

package com.scs.stuff;

import java.util.ArrayList;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListReadyObjectAdapter extends ArrayAdapter<ListReadyObject> {

    public ListReadyObjectAdapter(Context context, int textViewResourceId,
            ArrayList<ListReadyObject> lro) {
        super(context, textViewResourceId, lro);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LinearLayout v;
        v = new LinearLayout(getContext());
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        vi.inflate(R.layout.list_row, v, true);

        ListReadyObject o = getItem(position);

        if (o != null) {

            TextView tt = (TextView) v.findViewById(R.id.toptext);
            TextView bt = (TextView) v.findViewById(R.id.bottomtext);

            if (tt != null) {
                tt.setText(o.getDisplayText());
            }

            if (o.isLiving()) {
                if (bt != null) {
                    // set default text to be shown
                    // until the status thread completes
                    bt.setText("---");
                }
                // start a background thread to update Display State
                o.updateStatus();
                // why does this work
                new ObjectInterfaceHandler(position, o, v);

            } else {
                if (bt != null) {
                    bt.setText("Not Living");
                }
            }
        }
        return v;
    }

    // provides a way for the Object to call back to the list without
    // blocking the UI
    public class ObjectInterfaceHandler implements ListReadyObjectStatusListener {
        int position;
        ListReadyObject o;
        View v;

        private final Handler handler = new Handler();

        public ObjectInterfaceHandler(int position, ListReadyObject o, View v) {
            this.position = position;
            this.o = o;
            this.v = v;
            // register to observe an update from the Object
            o.registerObserver(this);
        }
        @Override
        public void objectInterfaceUpdate() {
            // called from the Object's observer pattern
            handler.post(updateBottomText);
        }
        // runnable to put the update on the UI Thread
        private Runnable updateBottomText = new Runnable() {
            @Override
            public void run() {
                TextView bt = (TextView) v.findViewById(R.id.bottomtext);
                if (bt != null) {
                    bt.setText(o.getStatusText());
                }
            }
        };
    }
}

ListReadyObject interface:

package com.scs.stuff;

public interface ListReadyObject {

    public void registerObserver(ListReadyObjectStatusListener o);

    public void removeObserver(ListReadyObjectStatusListener o);

    public void notifyObservers();

    public String getDisplayText();

    public String getStatusText();

    public boolean isLiving();

    public void updateStatus();

}

ListReadyObjectStatusListener interface:

package com.scs.stuff;

public interface ListReadyObjectStatusListener {

    public void objectInterfaceUpdate();

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:29:52+00:00Added an answer on May 28, 2026 at 2:29 pm

    It doesn’t (directly) make the view listen for callbacks.

    Here you see the ListReadyObject get passed into the constructor of ObjectInterfaceHandler:

    ListReadyObject o = getItem(position);
    ...
    new ObjectInterfaceHandler(position, o, v);
    

    In that constructor you find this:

    o.registerObserver(this);
    

    So the ObjectInterfaceHandler is actually the one listening to ListReadyObject. Then when it is notified of an update:

    @Override
    public void objectInterfaceUpdate() {
        // called from the Object's observer pattern
        handler.post(updateBottomText);
    }
    

    It posts a message to its own handler to call your Runnable which updates the view:

    private Runnable updateBottomText = new Runnable() {
        @Override
        public void run() {
            TextView bt = (TextView) v.findViewById(R.id.bottomtext);
            if (bt != null) {
                bt.setText(o.getStatusText());
            }
        }
    };
    

    This is a very common pattern called the Observer Pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.