mdeudon
mdeudon

Reputation: 51

Access to textview from threads

I have an activity with a textview, created from the layout.xml. Inside this activity I created a thread. I want want to use my textview from inside the thread but each time I do something like textview.setText() my program forces to close.

The question is : why I cannot access to textview from the thread ?

Upvotes: 0

Views: 411

Answers (1)

ingsaurabh
ingsaurabh

Reputation: 15269

The problem is You are trying to interfere in Ui Thread from a non UI thread so in order to do such things from non ui- thread

    runOnUiThread(new Runnable()
    {            
        @Override
        public void run()
        {
            // Add your GUI code here  like setText from your perspective              
        }
    });

Upvotes: 1

Related Questions