开发者

Access to textview from threads

开发者 https://www.devze.com 2023-02-15 18:36 出处:网络
I have an activity with a textview, created from the layout.xml. Inside this activity I created a thread.

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 d开发者_运维百科o something like textview.setText() my program forces to close.

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


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              
        }
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消