setText不适用于自定义Edittext [英] setText not working for a Custom Edittext

查看:103
本文介绍了setText不适用于自定义Edittext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用从github找到的不错的Material Design编辑文本: https://github.com/rengwuxian/MaterialEditText

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'
}

edittext xml定义如下:

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

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

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);
        }

以某种方式这不会更新UI上的文本.我也尝试过使用filePathValue.invalidate(),但这也无济于事.

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

任何帮助表示赞赏.

推荐答案

以这种方式尝试.

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

这篇关于setText不适用于自定义Edittext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆