【问题标题】:How to display (Highlight) value based on another array value in AutoCompleteTextView?如何根据 AutoCompleteTextView 中的另一个数组值显示(突出显示)值?
【发布时间】:2012-11-23 14:29:04
【问题描述】:

附加的是其中有 AutoCompleteTextView 的图像,我设置了客户名称的 ArrayAdapter(字符串数组)。现在,我想通过客户地址搜索客户名称(我有客户名称的字符串数组)(我有客户地址的字符串数组)。这意味着如果我在 AutoCompleteTextView 中键入“Ahemdabad”,它会显示地址为“Ahemdabad”的客户名称列表。那么,我该怎么做?..任何帮助将不胜感激。

【问题讨论】:

标签: java android user-interface


【解决方案1】:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<AutoCompleteTextView android:id="@+id/myautocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
/>
</LinearLayout>

AndroidAutoCompleteTextView.java

package com.AndroidAutoCompleteTextView;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class AndroidAutoCompleteTextView extends Activity implements TextWatcher{

AutoCompleteTextView myAutoComplete;
String item[]={
  "January", "February", "March", "April",
  "May", "June", "July", "August",
  "September", "October", "November", "December"
};

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       myAutoComplete = (AutoCompleteTextView)findViewById(R.id.myautocomplete);

       myAutoComplete.addTextChangedListener(this);
       myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, item));

   }

@Override
public void afterTextChanged(Editable arg0) {
 // TODO Auto-generated method stub

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
  int after) {
 // TODO Auto-generated method stub

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
 // TODO Auto-generated method stub

}
}

【讨论】:

  • 我想在用户在 AutoCompleteTextView 中输入他们的地址时显示客户姓名..
猜你喜欢
  • 1970-01-01
  • 2017-01-31
  • 1970-01-01
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
  • 1970-01-01
  • 2015-08-04
相关资源
最近更新 更多