How to update a TextView from within onPostExecute

后端 未结 2 772
渐次进展
渐次进展 2021-01-17 07:02

Need help here, about onPostExecute. If I want to put the update on textView what should be the code and what should I do?.

@Override
protected Value[] doIn         


        
2条回答
  •  孤城傲影
    2021-01-17 07:19

    Do as follows, save reference to TextView as member and use it in nested AsyncTask:

    public class YourActivity extends Activity{
    
        private TextView textView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.your_activity_layout);
            textView = (TextView)findViewById(R.id.yourTextViewID);
        ...
        }
    
        private YourAsyncTask extends AsyncTask{
        ...
            @Override
            protected void onPostExecute(Value[] variableValues) {
                if(textView != null)
                    textView.setText("your text");
    
             }
        }
    }
    

提交回复
热议问题