0

I have an existing project but that has recently started displaying the edittext wrong on a recent update. I'm not what has changed as this particular part of the app, in the screenshot below, didn't get changed so I'm expecting its some bug in the support libraries but not sure.

Basically the problem is that when the user enters text into an edittext, the hint text doesn't disappear it remains visible as shown in the screenshot below.

Screenshot showing problem

Below is the XML code for this particular layout

<?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>

The EditTexts are then populated programmatically using the following code

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();
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Boardy
  • 35,417
  • 104
  • 256
  • 447

2 Answers2

0

Maybe a text change listener could provide a quick fix

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("");
    }
});
samus
  • 6,102
  • 6
  • 31
  • 69
0

As @MikeM mentioned there is a bug in version 25.1.0 of the support library which caused this problem. I updated my gradle.build file to use version 25.3.0 of the support library and this has now rectified the problem.

Boardy
  • 35,417
  • 104
  • 256
  • 447