2014-06-05 17 views
1

我有以下AutoCompleteTextViewAutoCompleteTextview SINGLELINE的setText()的文本比視圖尺寸長會引起破詞語

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

輸入到這個AutoCompleteTextView經由我已經創建了一個「撥號器」佈局完成,從而這AutoCompleteTextViewandroid:enabled="false",爲了增加我的AutoCompleteTextView我使用下面的代碼的用戶輸入:

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(); 
    } 

每一件事情做工精細,除了一個奇怪的問題: 由於輸入是不是由設備的鍵盤,只有通過我的撥號與setText()完成,如果用戶點擊了很多的數字whihc比AutoCompleteTextView的規模最後一個數字被打破時間更長,同時繼續輸入更多的位數AutoCompleteTextView不向左滾動。奇怪的是,我試圖啓用它,並從設備的鍵盤輸入一些長時間的輸入,它可以很好地工作,長文本不會被破壞,滾動正在發生。既然不能使用設備的鍵盤就必須通過我的佈局和setText()提前

非常感謝來完成

編輯:

這裏是一個屏幕截圖: My dialer layout with broken digit at the end

+0

你期望什麼?你想通過手指滾動它,或者你想顯示字符串的結尾(並在開始時損壞) –

+0

@Demand我想顯示字符串的結尾(並開始損壞)我試過'android:ellipsize'它不工作。我覺得'setText()'沒有做什麼,而鍵盤的輸入確實是 – EviatarS

+0

看我的答案 –

回答

1

可以代替添加使用的setText的光標移動到結束。

0

我不知道如果這會工作,但你有沒有試圖把你的AutoCompleteTextView放在Horizo​​ntalScrollView中?

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

你能提供一個屏幕截圖,以便我能更好地理解你所遇到的問題嗎?

+0

嘿,我添加了一個屏幕截圖。我希望裏面的文本可以像'AutoCompleteTextView'本身一樣滾動 – EviatarS

+0

@EviatarS感謝您的屏幕截圖。在調用setText之後,這會將光標移動到最後並可能解決您的問題:_searchAutoCompleteTextView.setSelection(_searchAutoCompleteTextView.getText()。length()); – todd

+0

@EviatarS其實你可以使用append而不是setText,並且遊標會自動結束。 – todd

0

您需要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:gravity="right" 
      android:textSize="20sp" > 
    </AutoCompleteTextView>