现有代码和xml 代码
fromAutoComplete = new AutoComplete(
this, R.layout.fromautocomplete,
R.id.fromautocomplete);
fromAutoComplete.setNotifyOnChange(true);
fromAddress = (AutoCompleteTextView) findViewById(R.id.fromAddress);
fromAddress.setAdapter(fromAutoComplete);
fromAddress.setOnItemClickListener(this);
fromAddress.setOnFocusChangeListener(this);
fromAddress.setOnClickListener(this);
xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fromautocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:maxLines="2"
android:minLines="2"
android:singleLine="false"
android:text="sample text, a lot of text to encourage wrap text"/>
我需要自动完成功能来在listview上包装文本。所以我在自动完成周围添加了一个LinearLayout。这有效。现在,自动填充的列表视图已包装文本。 但是在选择非我的回叫时不会被称为。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/fromautocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:minLines="2"
android:scrollHorizontally="false"
android:singleLine="false"
android:text="sample text, a lot of text to encourage wrap text"/>
</LinearLayout>
答案 0 :(得分:0)
搞定了,
修复
id
LinearLayout
id
onItemClick
R.layout.<file>
XML(R.layout.fromautocomplete)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toautocompleteLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/toautocomplete"
代码
fromAutoComplete = new AutoComplete(this,
R.layout.fromautocomplete,
R.id.fromautocomplete);
fromAutoComplete.setNotifyOnChange(true);
OnItemClick
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if (view.getId() == R.id.fromautocompleteLayout) {
答案 1 :(得分:0)
您需要从LinearLayout
获取Textview@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
View v = (TextView)((LinearLayout )view).getChildAt(0);
String s = ((TextView) v).getText().toString();
//Do something with string s
}