使用这个库需要添加如下依赖
compile 'com.github.liang1075963999:searchablespinner:v1.1.1'
你还需要在你的app module下添加如下依赖
compile 'gr.escsoft.michaelprimez.revealedittext:RevealEditText:1.0.1'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
思维导图:
效果图如下:
代码片段:
mSimpleListAdapter = new SimpleListAdapter(getContext(), mStrings);
mSearchableSpinner = (SearchableSpinner) view.findViewById(R.id.SearchableSpinner);
mSearchableSpinner.setAdapter(mSimpleListAdapter);
mSearchableSpinner.setOnItemSelectedListener(mOnItemSelectedListener);
mSearchableSpinner.setStatusListener(new IStatusListener() {
@Override
public void spinnerIsOpening() {
mSearchableSpinner1.hideEdit();
mSearchableSpinner2.hideEdit();
}
@Override
public void spinnerIsClosing() {
}
});
private OnItemSelectedListener mOnItemSelectedListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(View view, int position, long id) {
Toast.makeText(getActivity(), "Item on position " + position + " : " + mSimpleListAdapter.getItem(position) + " Selected", Toast.LENGTH_SHORT).show();
string=(String)mSimpleListAdapter.getItem(position);
}
@Override
public void onNothingSelected() {
Toast.makeText(getActivity(), "Nothing Selected", Toast.LENGTH_SHORT).show();
}
};
private void initListValues() {
mStrings.add("星期一");
mStrings.add("星期二");
mStrings.add("星期三");
mStrings.add("星期四");
mStrings.add("星期五");
mStrings.add("星期六");
mStrings.add("星期日");
}
完整的项目为searchablespinner