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 8298775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:54:25+00:00 2026-06-08T15:54:25+00:00

Below is the CustomView class extending the View class. It works good statically. I

  • 0

Below is the CustomView class extending the View class. It works good statically.

I am clicking a button, it shows the targeted shelf, which I am headed to. Then I am clicking another button, it clears the targeted shelf and the map is back in its initial state.

What needs to be done is, this baby has to clear the targeted shelf by itself using some async calls, after xx seconds. And in the same fashion, when I begin to show my position on the map with an “X“, it has to refresh that “X” while I am walking.

The AsyncTask doesn’t seem to be the perfect solution for this. Do you have an idea on how the map should update itself?

Thanks in advance.

The CustomView:

public class CustomView extends View {
    ShapeDrawable roomFrame, targetShelfFrame, me;
    int halfMe;
    ArrayList<ShapeDrawable> shelfFrames;
    //(...)

    @Override
    protected void onDraw(Canvas canvas){
        super.onDraw(canvas);
        if(roomFrame != null)
            roomFrame.draw(canvas);
        for (ShapeDrawable shelfFrame : shelfFrames)
            shelfFrame.draw(canvas);
        if(targetShelfFrame != null)
            targetShelfFrame.draw(canvas);
        if(me != null)
            me.draw(canvas);
    }

    public void setRoom(Room room){
        roomFrame = new ShapeDrawable(new RectShape());
        roomFrame.getPaint().setColor(0xff74AC23);
        roomFrame.getPaint().setStyle(Style.STROKE);
        roomFrame.setBounds(10, 10, room.getWidth(), room.getHeight());
        invalidate();
    }

    public void setShelves(ArrayList<Shelf> shelves){
        shelfFrames = new ArrayList<ShapeDrawable>();
        for(int i = 0; i<shelves.size(); i++){
            ShapeDrawable shelfFrame = new ShapeDrawable(new RectShape());
            shelfFrame.getPaint().setColor(0xff74AC23);
            shelfFrame.setBounds(shelves.get(i).getXPosition(), shelves.get(i).getYPosition(), shelves.get(i).getWidth(), shelves.get(i).getHeight());
            shelfFrames.add(shelfFrame);
        }
        invalidate();
    }

    public void setTargetShelf(Shelf shelf){
        targetShelfFrame = new ShapeDrawable(new RectShape());
        targetShelfFrame.getPaint().setColor(Color.RED);
        targetShelfFrame.setBounds((int)(shelf.getXPosition()), (int)(shelf.getYPosition()),
                (int)((shelf.getXPosition() + shelf.getWidth())), 
                (int)((shelf.getYPosition() + shelf.getHeight())));
        invalidate();
    }

    public void clearTargetShelf(){
        targetShelfFrame = null;
        invalidate();
    }

    public void updateMyPosition(Position position){
        me = new ShapeDrawable(new OvalShape());
        me.getPaint().setColor(Color.GREEN);
        me.setBounds(position.getX() - halfMe, position.getY() - halfMe, 
            position.getX() + halfMe, position.getY() + halfMe);
    }
}

How I call it:

public void loadRoomPlan(Room room, ArrayList<Shelf> shelves){
    CustomView exampleView = (CustomView)findViewById(R.id.roomplan);
    exampleView.setRoom(room);
    exampleView.setShelves(shelves);
}
  • 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-06-08T15:54:26+00:00Added an answer on June 8, 2026 at 3:54 pm

    Actually, the easiest way (as far as I understand your goals) to solve your problem is to use Handler to perform a delayed execution on a UI thread.
    So what you need to do is:

    • Create Handler (globally for your custom view)
    • use postDelayed(Runnable, long) interface to run your shelf clean-up with certain delay

    Your code would look like:

    The CustomView:

    public class CustomView extends View {
        ShapeDrawable roomFrame, targetShelfFrame;
        ArrayList<ShapeDrawable> shelfFrames;
        Handler uiThread = new Handler();
        //(...)
    
        public void setTargetShelf(final Shelf shelf){
            targetShelfFrame = new ShapeDrawable(new RectShape());
            targetShelfFrame.getPaint().setColor(Color.RED);
            targetShelfFrame.setBounds((int)(shelf.getXPosition()), (int)(shelf.getYPosition()),
                (int)((shelf.getXPosition() + shelf.getWidth())), 
                (int)((shelf.getYPosition() + shelf.getHeight())));
            invalidate();
            uiThread.postDelayed(new Runnable()
            {
                @Override
                public void run()
                {
                    clearTargetShelf(shelf);            
                }
            }, 10000); //10 secs delay
    }
    

    Regarding the second part of your question (with walking ‘X’ on a map) I didn’t quite understand – what type of map are you using? Is it google map? Is it your own map? What does ‘walking’ mean? Is it real movement, or just some sort of game where you can move your character on the map? Please clarify

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

Sidebar

Related Questions

Currently, I have an NSStatusItem that, when clicked, shows a custom view below it.
I created a custom view, which has one button and one text field ,
I have a custom View , which consists of a button, and a view
I have a GridView with custom View in it, which is a Button and
Below is the code from internalRegister method of GCMRegistrar class static void internalRegister(Context context,
In the picture below, what type of view is used to create the 'turning
I have a project using a ViewPager which works correctly: I can page from
Below is a simplification of some code I have for a custom View .
First of all I began with the code below in my view controller but
I create a game which has a custom view derived from surfaceView. and in

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.