2017-07-08 2 views
0

Ich habe ein Layout mit einem TextInputLayout s Elemente und ich möchte Zähler von Zeichen aktivieren. Das Problem ist, dass es nicht funktioniert und ich kann den Zähler nicht sehen, wenn ich die App starte.TextInputLayout setCounterEnables funktioniert nicht - Android

Hier ist mein Layout:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorBackground" 
    android:paddingLeft="@dimen/create_step_padding" 
    android:paddingRight="@dimen/create_step_padding" 
    android:paddingTop="@dimen/create_step_padding"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!-- Shipper Text Area--> 
     <android.support.design.widget.TextInputLayout 
      android:id="@+id/shipper_layout" 
      android:layout_width="0dp" 
      android:layout_height="110dp" 
      android:background="@drawable/text_area_background" 
      android:paddingEnd="@dimen/text_input_layout_side_padding" 
      android:paddingStart="@dimen/text_input_layout_side_padding" 
      android:paddingTop="@dimen/text_input_layout_top_padding" 
      app:counterEnabled="true" 
      app:hintTextAppearance="@style/HintTextStyle" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent"> 

      <android.support.design.widget.TextInputEditText 
       android:id="@+id/shipper_field" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@null" 
       android:gravity="top|start" 
       android:hint="@string/shipper_field" 
       android:inputType="textMultiLine" 
       android:lines="5" 
       android:overScrollMode="always" 
       android:scrollbarStyle="insideInset" 
       android:scrollbars="vertical" /> 
     </android.support.design.widget.TextInputLayout> 


     <!-- Consignee Text Area--> 
     <android.support.design.widget.TextInputLayout 
      android:id="@+id/consignee_layout" 
      android:layout_width="0dp" 
      android:layout_height="110dp" 
      android:layout_marginTop="16dp" 
      android:background="@drawable/text_area_background" 
      android:paddingLeft="@dimen/text_input_layout_side_padding" 
      android:paddingTop="@dimen/text_input_layout_top_padding" 
      app:counterEnabled="true" 
      app:hintTextAppearance="@style/HintTextStyle" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/shipper_layout"> 

      <android.support.design.widget.TextInputEditText 
       android:id="@+id/consignee_field" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@null" 
       android:gravity="top|start" 
       android:hint="@string/consignee_field" 
       android:inputType="textMultiLine" 
       android:lines="5" 
       android:overScrollMode="always" 
       android:scrollbarStyle="insideInset" 
       android:scrollbars="vertical" /> 
     </android.support.design.widget.TextInputLayout> 

     <!-- Airport of Departure --> 

     <!-- Airport of Destination --> 

     <com.silverfix.dgdeditor.utils.views.AirportAutoCompleteEditText 
      android:id="@+id/aodep_field" 
      android:layout_width="217dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:layout_marginStart="8dp" 
      android:ems="10" 
      android:inputType="textPersonName" 
      android:text="Name" 
      app:layout_constraintBottom_toBottomOf="@+id/textView11" 
      app:layout_constraintHorizontal_bias="0.512" 
      app:layout_constraintLeft_toRightOf="@+id/textView11" 
      app:layout_constraintRight_toRightOf="parent" /> 

     <com.silverfix.dgdeditor.utils.views.AirportAutoCompleteEditText 
      android:id="@+id/aodes_field" 
      android:layout_width="217dp" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="textPersonName" 
      android:text="Name" 
      app:layout_constraintBottom_toBottomOf="@+id/textView12" 
      app:layout_constraintLeft_toLeftOf="@+id/aodep_field" /> 

     <TextView 
      android:id="@+id/textView11" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="32dp" 
      android:text="@string/aodep_field" 
      android:textAppearance="@style/DefaultTextStyle" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/consignee_layout" /> 

     <TextView 
      android:id="@+id/textView12" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="24dp" 
      android:text="@string/aodes_field" 
      android:textAppearance="@style/DefaultTextStyle" 
      app:layout_constraintLeft_toLeftOf="@+id/textView11" 
      app:layout_constraintTop_toBottomOf="@+id/textView11" /> 
    </android.support.constraint.ConstraintLayout> 
</ScrollView> 

Wie Sie sehen können, habe ich aktiviert app:counterEnabled in den TextInputLayout s. Dann versuche ich die Max Zeichen in meinem Code zu setzen.

Hier ist der Code:

shipperTextArea = (TextInputLayout) rootView.findViewById(R.id.shipper_layout); 
consigneeTextArea = (TextInputLayout) rootView.findViewById(R.id.consignee_layout); 

shipperTextArea.setCounterMaxLength(60); 
consigneeTextArea.setCounterMaxLength(60); 

Antwort

0

setzen nur den Zähler in XML-Dateien, fügen Sie diese:

<android.support.design.widget.TextInputLayout 
    app:counterMaxLength="60" 
    app:counterEnabled="true" 

ich denke, dass sie nicht in der Java-Klasse festlegen müssen.

Verwandte Themen