首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >EditText用户输入显示在提示文本的顶部

EditText用户输入显示在提示文本的顶部
EN

Stack Overflow用户
提问于 2017-03-16 21:51:31
回答 2查看 599关注 0票数 0

我有一个现有的项目,但最近开始在最近的更新中显示错误的edittext。我不知道有什么改变,因为在下面的截图中,应用程序的这一特定部分没有改变,所以我预计它会在支持库中出现一些错误,但不确定。

基本上,问题是当用户在edittext中输入文本时,提示文本不会消失,它仍然可见,如下面的屏幕截图所示。

以下是此特定布局的XML代码

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
    <include layout="@layout/toolbar" />
    <ScrollView
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
        <LinearLayout android:id="@+id/controlContainer"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical" />
    </ScrollView>
    <TextView android:id="@+id/noPrimaryKeyInfo"
       android:background="@color/api_error_background"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:text="@string/no_primary_key_available_therefore_updates_and_deletes_cannot_be_done"
       android:textStyle="bold"
       android:layout_gravity="center_horizontal"
       android:gravity="center_horizontal"
       android:layout_alignParentBottom="true"
       android:padding="5dp"/>
    <TextView android:id="@+id/lblUpgradeStatus"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:visibility="gone"/>
</LinearLayout>

然后使用以下代码以编程方式填充EditTexts

代码语言:javascript
运行
复制
Bundle bundle = getIntent().getExtras();
        indexAndFields = (HashMap<Integer, String>) bundle.getSerializable("indexAndFields");
        fieldAndValue = (HashMap<Integer, String>) bundle.getSerializable("fieldAndValue");
        currentTableName = bundle.getString("tableName");

        fieldDataList = rebuildFieldDataListFromJson(bundle.getString("tableAndDescription"));
        Log.d("RowEditor", bundle.getString("tableAndDescription"));
        lblNoPrimaryKeyInfo = (TextView)findViewById(R.id.noPrimaryKeyInfo);

        for (Integer data : fieldAndValue.keySet())
        {
            int index = data;

            FieldData fieldData = getFieldDataFromFieldName(indexAndFields.get(index));

            TextInputLayout textInputLayout = new TextInputLayout(this);

            EditText editText = new EditText(RowEditor.this);
            editText.setHint(indexAndFields.get(index));
            editText.setText(fieldAndValue.get(data));
            if (!purchaseUpgraded)
            {
                editText.setEnabled(false);
            }
            fieldData.setEditText(editText);
            fieldDataList.remove(index);
            fieldDataList.add(index, fieldData);

            textInputLayout.addView(editText);

            if (fieldData.getIsPrimaryKey())
            {
                isPrimaryKeyAvailable = true;
                primaryKeyColumn = indexAndFields.get(index);
                originalPrimaryKeyValue = fieldAndValue.get(data);
                lblNoPrimaryKeyInfo.setVisibility(View.GONE);
            }
            controlContainer.addView(textInputLayout);
        }
        //Check if primary key is available, if not, disable all controls and display notification
        disableControlIfNoPrimaryKey();
    }
EN

回答 2

Stack Overflow用户

发布于 2017-03-16 22:14:23

也许文本更改侦听器可以提供快速修复

代码语言:javascript
运行
复制
editText.addTextChangedListener(new TextWatcher() {
    @Override
    public void afterTextChanged(Editable s) {
        if(editText.Text == "")
        {
            editText.setHint(hint);
        }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        editText.setHint("");
    }
});
票数 0
EN

Stack Overflow用户

发布于 2017-03-17 05:51:35

正如@MikeM提到的,在支持库的25.1.0版本中有一个bug,导致了这个问题。我更新了我的gradle.build文件以使用25.3.0版本的支持库,现在已经解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42836011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档