runOnUiThread(new Runnable(){}) is undefined for the type new Thread(){}

前端 未结 3 1643
时光取名叫无心
时光取名叫无心 2021-01-01 18:31

Looking at the part:

runOnUiThread(new Runnable() {

I have the problem:

The method runOnUiThread(new Runnable(){}) is undef         


        
相关标签:
3条回答
  • 2021-01-01 19:24

    If you are using Fragments just add getActivity()

    Here replace :
    runOnUiThread(new Runnable() {
    By
    getActivity().runOnUiThread(new Runnable() {

    0 讨论(0)
  • 2021-01-01 19:37

    You have to setOnClickListener that you haven't set in your code like

    Button confirm = (Button) dialog.findViewById(R.id.btn_confirm);
    confirm.setOnClickListener(new OnClickListener() 
    {
    
        @Override
        public void onClick(View v)
        {
            your call to method...
        }
    });
    
    0 讨论(0)
  • 2021-01-01 19:38

    Write like this-

    ((Activity) context).runOnUiThread(new Runnable() {
        @Override
        public void run() {
            //Code for the UiThread
        }
    });
    

    For Fragment :

    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            //Code for the UiThread
        }
    });
    

    This may help you.

    0 讨论(0)
提交回复
热议问题