setText not working for a Custom Edittext

≯℡__Kan透↙ 提交于 2020-02-03 11:15:36

问题


I am using a nice Material design edit text which I found from github: https://github.com/rengwuxian/MaterialEditText

and updated the dependency section as :

dependencies {
   compile 'com.rengwuxian.materialedittext:library:2.0.3'
}

The edittext xml is defined as follows:

    <com.rengwuxian.materialedittext.MaterialEditText
        android:id="@+id/device_file_location_value"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_file_location"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:enabled="true"
        android:focusable="false"
        android:clickable="true"
        app:met_floatingLabel="normal"
        app:met_floatingLabelText="@string/file_location"
        app:met_singleLineEllipsis="true"
        app:met_baseColor="#FCFBE3"
        app:met_primaryColor="#FCFBE3"/>

So I am expecting to fill the value of the edit text programatically by browsing the file system. So the edittext is clickable but not focusable and hence user cannot edit the path of file received. Now this (device_file_location_value) edit text is updated by a value received from other fragment(the fragment that implements the file browser) and is updated as follows in the onCreateView of its fragment:

        Bundle bundle = getArguments();
        String filePath = bundle.getString(FileBrowserFragment.PARAM_FILE_PATH);
        if (filePath != null) {
            filePathValue.setText(filePath);
            bundle.remove(FileBrowserFragment.PARAM_FILE_PATH);
        }

Somehow this is not updating the text on the UI. I have also tried using filePathValue.invalidate() but that didn't help either.

Any help appreciated.


回答1:


Try in this way.

filePathValue.post(new Runnable() {
                @Override
                public void run() {
                    filePathValue.setText(filePath);
                }
            })


来源:https://stackoverflow.com/questions/34949137/settext-not-working-for-a-custom-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!