3

I want to android:ellipsize the text in AutoCompleteTextView. Tried the following code, but it not working.

Can someone help me?

Here is the code:

<AutoCompleteTextView
          android:id="@+id/address_text"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:completionThreshold="3"
          android:imeOptions="actionSearch"
          android:imeActionLabel="Search"
          android:textSize="16sp"
          android:singleLine="true"
          android:ellipsize="end" />
Ravi
  • 34,851
  • 21
  • 122
  • 183
Kiran
  • 31
  • 2

4 Answers4

1

I think AutocompleteTextView is not feasible for ellipSize but we can set ellipsize customize,Below is the code,

        String fullText = "Give your text here";
        int width = autocompleteTextview.getMeasuredWidth() - (autocompleteTextview.getPaddingLeft()+autocompleteTextview.getPaddingRight());

        String truncatedText = TextUtils.ellipsize(mFullText, autocompleteTextview.getPaint(), width, TextUtils.TruncateAt.END).toString();
        if(truncatedText!=null&& truncatedText.length()>0){
            autocompleteTextview.setText(truncatedText);
        }
Vinoj Vetha
  • 726
  • 6
  • 8
0

android:completionThreshold="1"

-1
<AutoCompleteTextView
        android:id="@+id/product"
        android:layout_width="110dp"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:gravity="center"
        android:imeOptions="flagNoExtractUi"
        android:tag="product"
        android:ellipsize="marquee"
        android:singleLine="false" />

In the adapter or any class , where ever you using the autotextview set Threshold to 1

vish
  • 168
  • 2
  • 13
  • ,where are you setting ellipsize property? – Kiran Sep 18 '13 at 06:17
  • see this it might help [link](http://stackoverflow.com/questions/2160619/android-ellipsize-multiline-textview) – vish Sep 18 '13 at 06:37
  • it's not working for me. My app force closes, when I use `android:ellipsize="marquee"` on my autocompletetextview. Please help me out.. – njnjnj Aug 17 '14 at 15:14
-1
private String mclientName;

Put the code in oncreate()

mClientName=new ArrayList<String>(); 
mClientName.add("abc");
mClientName.add("abc");
mClientName.add("abc");
mClientName.add("abc");
mClientName.add("abc");


((AutoCompleteTextView)findViewById(R.id.etschoolname)).setText(mcollegeName
                                    .equalsIgnoreCase("") ? "" : mcollegeName);
                            ArrayAdapter<String> adapter = 
                                    new ArrayAdapter<String>(UserEditEducationActivity.this, android.R.layout.simple_dropdown_item_1line,mClientName);
                            ((AutoCompleteTextView)findViewById(R.id.etschoolname)).setThreshold(1);
                            ((AutoCompleteTextView)findViewById(R.id.etschoolname)).setAdapter(adapter);
                            ((AutoCompleteTextView)findViewById(R.id.etschoolname)).setOnItemClickListener(new OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> arg0,
                                        View arg1, int arg2, long arg3) {
                                    // TODO Auto-generated method stub

                                    Toast.makeText(getApplicationContext(),(CharSequence)arg0.getItemAtPosition(arg2), Toast.LENGTH_LONG).show();
                            }
                            });

**

and xml

**

<AutoCompleteTextView 
                    android:id="@+id/etschoolname"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/header"
                    android:layout_margin="10dip"

                    android:hint=""
                    android:singleLine="true"
                    android:includeFontPadding="false"
                    android:maxLength="120"
                    android:paddingBottom="-10dip" />
Amit kumar
  • 1,585
  • 2
  • 16
  • 27