gpt4 book ai didi

java - 如何在 AutoCompleteTextView 中基于另一个数组值显示(突出显示)值?

转载 作者:行者123 更新时间:2023-12-01 05:02:04 25 4
gpt4 key购买 nike

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

最佳答案

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

}
}

关于java - 如何在 AutoCompleteTextView 中基于另一个数组值显示(突出显示)值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13264433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com