Home > Mobile >  Questions about refresh textview in fragments
Questions about refresh textview in fragments

Time:10-04

I'm in a fragment1
Perform button key event, need to refresh the contents of the textview
About the following
 
BtnC. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v)
{
Textview1. Settext="1111111";
//a
Textview1. Settext="2222222";
//a
Textview1. Settext="3333333";
//a
Textview1. Settext="4444444";
}

In fact, the above code implementation, button interface feign death, textview1 displays only the last of the "4444444"
So I add the following code
 
HandlerThread HandlerThread;
Private static String="" TT;

The class HandlerThread extends Thread
{
Handler mHandler;
HandlerThread Handler (h)
{
MHandler=h;
}
Public void the run ()
{
Byte status;
The Message MSG.
While (true)
{
Try
{
Thread.sleep (100);
}
Catch InterruptedException (e) {e.p rintStackTrace (); }
{
MSG=handler. ObtainMessage (0, "");
MHandler. SendMessage (MSG);
}
}
}
}

Final Handler Handler=new Handler ()
{
Public void handleMessage (Message MSG)
{
The switch (MSG. What)
{
Case 0:

If (TV. Length () & gt; 0)
{
Textview1. SetText (TV);
}
break;

Default:

break;
}
}
};

BtnC. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v)
{

TT="1111111";
//a
TT="2222222";
//a
TT="3333333";
//a
TT="4444444";
}

Add
in onCreate
 
HandlerThread=new handlerThread (handler);
HandlerThread. Start ();

Still no
Only see the last show of "44444444"
Refresh too fast?
Or what reason?

CodePudding user response:

The
refer to the original poster SUMI_SUMI response:
I
in a fragment1Perform button key event, need to refresh the contents of the textview
About the following
 
BtnC. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v)
{
Textview1. Settext="1111111";
//a
Textview1. Settext="2222222";
//a
Textview1. Settext="3333333";
//a
Textview1. Settext="4444444";
}

In fact, the above code implementation, button interface feign death, textview1 displays only the last of the "4444444"
So I add the following code
 
HandlerThread HandlerThread;
Private static String="" TT;

The class HandlerThread extends Thread
{
Handler mHandler;
HandlerThread Handler (h)
{
MHandler=h;
}
Public void the run ()
{
Byte status;
The Message MSG.
While (true)
{
Try
{
Thread.sleep (100);
}
Catch InterruptedException (e) {e.p rintStackTrace (); }
{
MSG=handler. ObtainMessage (0, "");
MHandler. SendMessage (MSG);
}
}
}
}

Final Handler Handler=new Handler ()
{
Public void handleMessage (Message MSG)
{
The switch (MSG. What)
{
Case 0:

If (TV. Length () & gt; 0)
{
Textview1. SetText (TV);
}
break;

Default:

break;
}
}
};

BtnC. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v)
{

TT="1111111";
//a
TT="2222222";
//a
TT="3333333";
//a
TT="4444444";
}

Add
in onCreate
 
HandlerThread=new handlerThread (handler);
HandlerThread. Start ();

Still no
Only see the last show of "44444444"
Refresh too fast?
Or what reason?

You directly to the Thread. Sleep (5000);
Don't know whether because the refresh too fast

CodePudding user response:

You call in a code block in main line synchronization Settings, it is only the last one to take effect, you have to through the child thread callback main thread updates, or use a Handler postDelay method to achieve the effect that you want to
  • Related