WEB开发网
开发学院手机开发Android 开发 通过改写ArrayAdapter 用AutoCompleteTextView 实... 阅读

通过改写ArrayAdapter 用AutoCompleteTextView 实现汉字和拼音双向关联

 2010-07-15 20:43:00 来源:WEB开发网   
核心提示:this.mDropDownResource = resource;}/*** {@inheritDoc}*/@Overridepublic View getDropDownView(int position, View convertView, ViewGroup parent) {return createView

this.mDropDownResource = resource;

}

/**

* {@inheritDoc}

*/

@Override

public View getDropDownView(int position, View convertView, ViewGroup parent) {

return createViewFromResource(position, convertView, parent, mDropDownResource);

}

/**

* Creates a new ArrayAdapter from external resources. The content of the array is

* obtained through {@link android.content.res.Resources#getTextArray(int)}.

*

* @param context The application's environment.

* @param textArrayResId The identifier of the array to use as the data source.

* @param textViewResId The identifier of the layout used to create views.

*

* @return An ArrayAdapter.

*/

public static ArrayAdapter createFromResource(Context context,

int textArrayResId, int textViewResId) {

CharSequence[] strings = context.getResources().getTextArray(textArrayResId);

return new ArrayAdapter(context, textViewResId, strings);

}

/**

* {@inheritDoc}

*/

public Filter getFilter() {

if (mFilter == null) {

mFilter = new ArrayFilter();

}

return mFilter;

}

/**

*

An array filter constrains the content of the array adapter with

* a prefix. Each item that does not start with the supplied prefix

* is removed from the list.

*/

private class ArrayFilter extends Filter {

@Override

protected FilterResults performFiltering(CharSequence prefix) {

FilterResults results = new FilterResults();

if (mOriginalValues == null) {

synchronized (mLock) {

上一页  2 3 4 5 6 7 8 9  下一页

Tags:通过 改写 ArrayAdapter

编辑录入:coldstar [复制链接] [打 印]
赞助商链接