bill.xml代码:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center">
<AutoCompleteTextView
android:id="@+id/ACTsearch"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_weight="0.8"
android:background="@null"
android:completionThreshold="1"
android:dropDownHeight="wrap_content"
android:dropDownWidth="wrap_content"
android:hint="输入要模糊查询的数据"
android:imeOptions="actionSearch"
android:maxLength="12"
android:paddingLeft="5dp"
android:singleLine="true"
android:textColor="#317F6D"
android:textColorHint="#317F6D"
android:textSize="14sp"
android:theme="@style/MyEditText"
/>
</LinearLayout>
bill.java代码:
AutoCompleteTextView ACTsearch;//源单编号
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_distribution_bill);
ACTsearch = (AutoCompleteTextView) findViewById(R.id.ACTsearch);
//模糊查询选中
ACTsearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
for (int g = 0; g < FSNumberList.size(); g++) {//FSNumberList数据源
if (parent.getItemAtPosition(position).toString().equals(FSNumberList.get(g))) {
spiSnumber.setSelection(g, true);//默认选中项
ACTsearch.setHint("" + FSNumberList.get(g));
ACTsearch.setText("");
break;
}
}
}
});
}
private void GetFSNumber() {
//FSNumber是Spinner
FSNumberIDArr.add("0");
FSNumberList.add("无");
FSNumberIDArr.add("2");
FSNumberList.add("有");
FSNumberIDArr.add("3");
FSNumberList.add("无有");
FSNumberIDArr.add("4");
FSNumberList.add("应该没");
SearchAdapter<String> adapter1 = new SearchAdapter<String>(bill.this, android.R.layout.simple_list_item_1, FSNumberList, SearchAdapter.ALL); ACTsearch.setAdapter(adapter1);
spiSnumber.setAdapter(adapterFSNumber);
}
博客内容介绍了如何对Android的AutoCompleteTextView进行模糊搜索的简便封装,提供了bill.xml和bill.java的相关代码示例,主要关注于FSNumber Spinner的功能实现。


被折叠的 条评论
为什么被折叠?



