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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:59:35+00:00 2026-05-30T12:59:35+00:00

I am trying to draw a rectangle where I am initially providing it values

  • 0

I am trying to draw a rectangle where I am initially providing it values from Activity class and then trying to change its coordinates from a different class.. As far as I am concerned the logic is right, but the invalidate is not working.. I did substantial research but still cannot make it work..

RectangleActivity.java

public class RectangleActivity extends Activity {

  private Point dStart = null;
  private Point dEnd = null;
  final private Handler handler = new Handler();
  Check check = new Check(this);
  Draw draw ;

  Runnable mUpdate = new Runnable()
    {
    public void run()
    {           
     Toast.makeText(getApplicationContext(), "update Called", Toast.LENGTH_LONG).show();
      check.update();           
    }
 };
      @Override
       public void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        dStart = new Point(0,0);
        dEnd = new Point(60,60);
        draw = new Draw(this,dStart,dEnd);
        setContentView(draw);
        handler.postDelayed(mUpdate, 4000); 
      } 
 }

Check.java

    public class Check 
    {

  private Point start = new Point(80,80);
  private Point end = new Point(150,150);
  private Context context;

  public Check(Context context)
  {
    this.context =context;      
  } 
    void update() 
  { 
    Log.d("Aditi", "Update Called");
    Draw draw = new Draw(context);
    draw.reDraw(start,end);     
  } 
 }

Draw.java

    public class Draw extends View
    {   
 private Paint paint = null;
 private Point start = null;
 private Point end = null;  

 public Draw(Context context) 
  {
    super(context);     
    paint();    
  }     
  public Draw(Context context, Point start, Point end) 
  {
    super(context);

    this.start= start;
    this.end = end;
    paint();
  } 

   protected void onDraw(Canvas canvas)
   {
    super.onDraw(canvas);
    canvas.drawRect(start.x,start.y,end.x,end.y,paint);
    Log.d("Aditi", "OnDraw Called");
    System.out.println("StartX in ondraw is: "+start.x);
    System.out.println("StartY in ondraw is: "+start.y);
    System.out.println("EndX in ondraw is: "+end.x);
    System.out.println("EndY in ondraw is: "+end.y);    
  }

  public void reDraw(Point Start, Point End)
  {
    Log.d("Aditi", "Redraw Called");
    this.start = Start;
    this.end = End;
    invalidate();
    Log.d("Aditi", "Invalidate  Called");
    System.out.println("StartX in redraw is: "+start.x);
    System.out.println("StartY in redraw is: "+start.y);
    System.out.println("EndX in redraw is: "+end.x);
    System.out.println("EndY in redraw is: "+end.y);        
   }    
     public void paint()
   {
    paint= new Paint();     
    paint.setColor(Color.YELLOW);
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
  }   
}

please feel free to point me out what am I doing wrong.. Thanks in advance..

  • 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-30T12:59:37+00:00Added an answer on May 30, 2026 at 12:59 pm

    In above problem, in onCreate() you took a view using draw = new Draw(this,dStart,dEnd);
    and then used in setContentView(draw), but when update() called you again created an object of Draw by using Draw draw = new Draw(this,dStart,dEnd); and call draw.reDraw(start, end) on second draw object, so the instance used in setContentView() is not invalidated, And second draw view object get invalidated but it did not passed in setContentView(), so it is not visible on ui: your solution is just

        void update() {
        //    Draw draw = new Draw(context);  //remove this
            draw.reDraw(start, end);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am simply trying to draw a rectangle inside of a panel using flex4.
I am trying to just draw a Rectangle on a PictureBox that is on
I'm currently trying to draw shapes with 2D Arrays. In my class there is
I am trying to draw rectangle on top of image and I am having
I'm trying to draw a rectangle on the canvas with the center at the
I am writing an Eclipse RCP-based application and am trying to draw a rectangle
I am trying to draw a rectangle on a windows mobile phone. Draw the
i am trying to draw a rectangle when i press mouse left button and
I'm trying to let people draw a rectangle on Google Maps and store the
i'm trying to draw a rectangle with semi-circles at either end. i'm also trying

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.