AutoCompleteTextview singleLine setText() with text longer than view size will cause broken words

StackOverflow https://stackoverflow.com//questions/24053739

  •  21-12-2019
  •  | 
  •  

Question

I have the following AutoCompleteTextView :

  <AutoCompleteTextView
                android:id="@+id/contact_list_auto_complete_text_view"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:enabled="false"
                android:hint=" Enter number"
                android:singleLine="true"
                android:textSize="20sp" >
  </AutoCompleteTextView>

The input to this AutoCompleteTextView is done via a "Dialer" Layout I've created , thus this AutoCompleteTextView is android:enabled="false" and in order to add the user input on my AutoCompleteTextView I use the following code :

   String mText =_searchAutoCompleteTextView.getText().toString()+_dialer_digits[position]; //the digit the user clicked upon 
  _searchAutoCompleteTextView.setText(mText);
  _searchAutoCompleteTextView.performCompletion();
  if(_searchAutoCompleteTextView.getText().toString().length()>2 &&  _searchAutoCompleteTextView.getAdapter().getCount()> 0)
  {
    _searchAutoCompleteTextView.showDropDown();
  }

Every thing is working fine except a weird issue : Since the input is not done by the device's keyboard and only by my dialer with setText() , if the user clicks alot of digits whihc are longer than the AutoCompleteTextView's size last digit is broken and while continuing to input more digits the AutoCompleteTextView does not scroll left. The weird thing about it is that I've tried to enable it and put some long input from the device's keyboard it works perfectly , long text is not broken and scrolling is happening. Since I cannot use the device's keyboard it must be done via my layout and setText()

Many thanks ahead

EDIT:

here is a screen shot : My dialer layout with broken digit at the end

Was it helpful?

Solution

You can use append instead of setText to move the cursor to the end.

OTHER TIPS

I'm not sure if this will work but have you tried to put your AutoCompleteTextView in a HorizontalScrollView?

<HorizontalScrollView android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <AutoCompleteTextView
            android:id="@+id/contact_list_auto_complete_text_view"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:hint=" Enter number"
            android:singleLine="true"
            android:textSize="20sp" >
    </AutoCompleteTextView>

</HorizontalScrollView>

Can you provide a screen shot so I can better understand the issue you are having?

You need to set Gravity of AutocompleteTextVIew to right:

<AutoCompleteTextView
            android:id="@+id/contact_list_auto_complete_text_view"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:hint=" Enter number"
            android:singleLine="true"
            android:gravity="right"
            android:textSize="20sp" >
    </AutoCompleteTextView>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top