Refreshing a page<view> in android

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Refreshing a page<view> in android

Postby Prashantk » Tue Nov 04, 2008 11:05 am

[font=Arial] [/font]

hi all,

i m new to android and i will like to know if there is any function provided for refreshing a page <view>or any other utility? say i have text view on my page and the text is continuously updating then i need to show the updated page with updated text.


thanks in advance,
Prashant
Appetite for development
Prashantk
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Nov 04, 2008 10:10 am
Location: Pune,India

Top

Postby MrSnowflake » Tue Nov 04, 2008 12:40 pm

I don't really understand you. If you are talking about a webpage, you can reload it using javascript. If you are talking about a TextView, then it's automatically updated. If you are talking about some custom view, you probably have to call View.invalidate().
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Prashantk » Tue Nov 04, 2008 1:01 pm

MrSnowflake wrote:I don't really understand you. If you are talking about a webpage, you can reload it using javascript. If you are talking about a TextView, then it's automatically updated. If you are talking about some custom view, you probably have to call View.invalidate().


hi Mr.Sf,
thanks for ur kind information.
what i want to say is if my page is displaying some text which is being fetched from external resource , like cricket match score, being updated after every 1 minute , then how can i refresh my page for new display?
Appetite for development
Prashantk
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Nov 04, 2008 10:10 am
Location: Pune,India

Postby MrSnowflake » Tue Nov 04, 2008 1:13 pm

Have an update method fetch the new data from the source and update the textview.

Use a Handler to delay the update Runnable.
And have the Runnable postDelay itself on the handler.
In your onCreate (where this.handler is a private Handler hander):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.handler = new Handler();
  2.  
  3. handler.postDelayed(myRunnable, 1000);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

and a somewhere else in the class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Runnable updateSource = new Runnable() {
  2.  
  3. public void run() {
  4.  
  5.   //get the stuff from the source
  6.  
  7.  
  8.  
  9.   //add self to handler
  10.  
  11.   handler.postDelayed(this, 1000);
  12.  
  13. }
  14.  
  15. };
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Why use Handler? Because Handler allows you to do threading stuff inside the main thread, which allows for less memory usage and probably lower battery usage.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests