Why can't I set text to an Android TextView?

前端 未结 8 2034
孤城傲影
孤城傲影 2020-12-31 03:04

I\'m having a problem with setting text to a TextView:

TextView android:editable = \"true\".

In my .java it seems like that this should wor

8条回答
  •  时光说笑
    2020-12-31 03:36

    You set the text to a field that was rendered in another instance of your activity residing in cash,say when it was landscape oriented. Then it was recreated due to some reason. You need to set the text in an unusual way by saving the string to SharedPreferences and force relaunch the activity using recreate(), say for mOutputText:

    @Override
    protected void onResume() {
        super.onResume();
        String sLcl=mPreferences.getString("response","");
        if(!sLcl.isEmpty()){
            mOutputText.setText(sLcl);
            mPreferences.edit().putString("response","").commit();
        }
    }
    
    private void changeText() {
        mPreferences.edit().putString("response",responseText).commit();
        recreate();
    }
    @Override
    protected void onActivityResult(
            int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case CAPTURE_MEDIA_RESULT_CODE:
                if (null == data || null == data.getData()) {
                   showMessage("Sorry. You didn't save any video");
                } else {
                    videoUri = data.getData();
                    mProgress = new ProgressDialog(this);
                    mProgress.setMessage("Uploading onYoutube ...");
    
                    authorizeIt();// SAY YOU CALL THE changeText() at the end of this method
                }
                break;
        }
    }
    

提交回复
热议问题