How do I dynamically update the content of TextView in Android development?

Source: Internet
Author: User


==================== Problem Description ====================
I want to update textview content dynamically, but nothing happens. There is no relevant code.
==================== Solution 1====================
Write a timer. or write a thread. It's time to update it in the interval.
==================== Solution 2====================
Reference 2 floor Tyaathome's reply:
Quote: Quote 1 floor peijiangping1989 reply:

Write a timer. or write a thread. It's time to update it in the interval.

There is no similar code example for me to look at.

Create a new thread to update the values inside the TextView, and then use handler to update the interface!
==================== Solution 3====================
Class Testthread extends thread{public void run () {Message message = new Message ();        Mhandler.sendmessage (message); }}//Update in Handler uiprivate Handler mhandler = new Handler () {public void Handlemessage (Message msg) {text        View.settext ("You want to change the content");      }; };

And then in your code, execute this thread
==================== Solution 4====================
 private final timer timer = new timer (); private timertask  Task; handler handler = new handler ()  {      @Override      public void handlemessage (message msg)  {          // TODO Auto-generated method stub          textview.settext ("XXXX");         Super.handlemessage (msg);      }};task = new timertask ()  {       @Override      public void run ()  {          // TODO Auto-generated method stub          message message = new message ();          message.what = 1;          Handler.sendmessage (message);      } }; timer.schedule (task, 1000,  1000); 


Or that's fine.


==================== Solution 5====================
Mtestingbutton.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
To begin the testing of Open-short.
Testdialog = Progressdialog.show (Initmassage.this, "", "Don t touch the Screen,open-short testing ...", true, false);
TimerTask task = new TimerTask () {
public void Run () {
Execute the Task
Testdialog.cancel ();
Mshorttestno.settext ("Pass");
System.out.println ("1");
}
};
Timer timer = new timer ();
Timer.schedule (task, 6000);
System.out.println ("2");
}

});


I use the above why cannot change the value of TextView after delay 6s to "Pass", the system will automatically crash!

How do I dynamically update the content of TextView in Android development?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.