自动提示的两个问题,急救。。谢谢

如题了,自动提示不知道怎么让用户已经输入的字变成其它颜色,比如:
用户输入:ya
下面的提示应该是:
[color=red]ya[/color]rine
[color=red]ya[/color]xxx
另外还有一个地方不懂,比如我的名字是张三,我想用户输入zs也可以显示出来。
我数据库中存了张三的拼音缩写,但是怎么才能实现这个功能呢?我现在只能:
用户输入:zs
下面提示:[color=red]zs[/color] 张三
而我想要的是
用户输入:zs
下面提示:张三 而不是"[color=red]zs[/color] 张三"

如下图:
[img]http://dl.iteye.com/upload/attachment/531935/49837bd7-ace6-3fe4-97e6-6ca976305d10.jpg[/img]
急救。。。。。

[url]http://renpeng301.iteye.com/admin/blogs/1142199
[/url]

[img]http://dl.iteye.com/upload/attachment/532214/37ab924b-c257-367d-b7dd-efbe5a6911f9.png
[/img]
[img]http://dl.iteye.com/upload/attachment/532216/da3da6de-4a52-3cce-ac86-d33869e70ca5.png
[/img]

你这个是用的系统自带的搜索框架?
还是自己写的组件?

还有你数据库保存的一个字段内容存储的是“zs张三”???
还是分2个字段存储“zs”“张三”??

如果用这个控件,可以首先自定义CursorAdapter
[code="java"]
//假设如你的数据库表名users(id,pycode,username,)
private class MyCursorAdpter extends CursorAdapter {

private int id; //

 public MyCursorAdpter(Context context, Cursor c, int col) {  
     super(context, c);  
     this.id= col;  
 }  
 @Override  
 public View newView(Context context, Cursor cursor, ViewGroup parent) {  
     final LayoutInflater inflater = LayoutInflater.from(context);  
     final TextView view = (TextView) inflater.inflate(  
             android.R.layout.simple_dropdown_item_1line, parent, false);  
     view.setText(cursor.getString(columnIndex));  
     return view;  
 }  
 @Override  

// bindView把cursor的数据绑定在view里
public void bindView(View view, Context context, Cursor cursor) {

//
((TextView) view).setText(cursor.getString(username));

}

 @Override  
 public String convertToString(Cursor cursor) {  

convertToString会把view的数据转换为AutoCompleteTextView显示的文字
return cursor.getString(name);

}

@Override

//这个方法查询数据库。返回结果集
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {

if (constraint != null) {

String selection = "pycode \'" + constraint.toString() +"%\'";

return sqlite.query("users", columns, selection, null, null, null, null);

}

else {

return null;

}

}

}

//总体的思路是。根据pucode查数据库。根据返回的Cursor ,将字段username的值填充到AutoCompleteTextView
[/code]

:D 如果你要关键字高亮那么这个得在

[code="java"]

@Override

10. public View newView(Context context, Cursor cursor, ViewGroup parent) {

11. final LayoutInflater inflater = LayoutInflater.from(context);

12. final TextView view = (TextView) inflater.inflate(

13. android.R.layout.simple_dropdown_item_1line, parent, false);

//在这个定法处理, constraint.toString()可以得到你的输入的关键字,
然后你把关键字处理下,简单的方法是html标签,将字体颜色处理
14. view.setText(cursor.getString(columnIndex));

15. return view;

16. }

[/code]

查询出来的结果进行一定的处理
如果两个字段,那是不是你把这个字段合并处理过了

private int id; // columnIndex
这个搞错了,这个应该是你要显示的字段。在数据库的列索引
view.setText(cursor.getString(columnIndex));

((TextView) view).setText(cursor.getString(columnIndex));

return cursor.getString(columnIndex);

这个都是这样的

:D 我在博客写了一下demo,有附件
http://renpeng301.iteye.com/admin/blogs/1142199
[img]http://dl.iteye.com/upload/attachment/532214/37ab924b-c257-367d-b7dd-efbe5a6911f9.png
[/img]
[img]http://dl.iteye.com/upload/attachment/532216/da3da6de-4a52-3cce-ac86-d33869e70ca5.png
[/img]