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

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

 2010-07-15 20:43:00 来源:WEB开发网   
核心提示:** @param item The item to retrieve the position of.** @return The position of the specified item.*/public int getPosition(T item) {return mObjects.indexOf(item

*

* @param item The item to retrieve the position of.

*

* @return The position of the specified item.

*/

public int getPosition(T item) {

return mObjects.indexOf(item);

}

/**

* {@inheritDoc}

*/

public long getItemId(int position) {

return position;

}

/**

* {@inheritDoc}

*/

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

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

}

private View createViewFromResource(int position, View convertView, ViewGroup parent,

int resource) {

View view;

TextView text;

if (convertView == null) {

view = mInflater.inflate(resource, parent, false);

} else {

view = convertView;

}

try {

if (mFieldId == 0) {

// If no custom field is assigned, assume the whole resource is a TextView

text = (TextView) view;

} else {

// Otherwise, find the TextView field within the layout

text = (TextView) view.findViewById(mFieldId);

}

} catch (ClassCastException e) {

Log.e("ArrayAdapter", "You must supply a resource ID for a TextView");

throw new IllegalStateException(

"ArrayAdapter requires the resource ID to be a TextView", e);

}

text.setText(getItem(position).toString());

return view;

}

/**

*

Sets the layout resource to create the drop down views.

*

* @param resource the layout resource defining the drop down views

* @see #getDropDownView(int, android.view.View, android.view.ViewGroup)

*/

public void setDropDownViewResource(int resource) {

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

Tags:通过 改写 ArrayAdapter

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