我有一个现有的项目,但最近开始在最近的更新中显示错误的edittext。我不知道有什么改变,因为在下面的截图中,应用程序的这一特定部分没有改变,所以我预计它会在支持库中出现一些错误,但不确定。
基本上,问题是当用户在edittext中输入文本时,提示文本不会消失,它仍然可见,如下面的屏幕截图所示。

以下是此特定布局的XML代码
<?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
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();
}发布于 2017-03-16 22:14:23
也许文本更改侦听器可以提供快速修复
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("");
}
});https://stackoverflow.com/questions/42836011
复制相似问题