我想android:ellipsize
AutoCompleteTextView
中的文字。试过以下代码,但它不起作用。
有人能帮我吗?
这是代码:
<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" />
我认为AutocompleteTextView对于ellipSize是不可行的,但我们可以设置ellipsize自定义,下面是代码,
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);
}
<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" />
在适配器或任何类中,您使用autotextview将Threshold设置为1
private String mclientName;
将代码放在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();
}
});
**
和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" />