setText 不适用于自定义 Edittext

setText not working for a Custom Edittext

我正在使用从 github 中找到的一个很好的 Material 设计编辑文本:https://github.com/rengwuxian/MaterialEditText

并将依赖项部分更新为:

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

编辑文本xml定义如下:

    <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"/>

所以我希望通过浏览文件系统以编程方式填充编辑文本的值。所以 edittext 是可点击但不可聚焦的,因此用户无法编辑接收到的文件的路径。现在这个 (device_file_location_value) 编辑文本由从其他片段(实现文件浏览器的片段)接收到的值更新,并在其片段的 onCreateView 中更新如下:

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

不知怎的,这并没有更新 UI 上的文本。我也尝试过使用 filePathValue.invalidate() 但这也没有帮助。

感谢任何帮助。

这样试试

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