最近在做个聊天软件 实现了弹出表情选择表情插入EditText
现在想实现用快捷键显示表情 像QQ一样输入/wx 就出现一个微笑表情 
实现了写/wx出现微笑表情 接着写/wx就不行了 我郁闷了 帅哥.美女们帮帮忙
代码如下
  public class MainActivity extends Activity {
private static String TAG="MainActivity";
private Button expressionButton;
private LayoutInflater inflater;
private GridView mGridView;
private EditText et;
private Dialog dialog;
//预定义的系统表情
private int[]face=new int[]
{ R.drawable.smiley_b_close,R.drawable.smiley_colon_apostrophe_open,
R.drawable.smiley_colon_close,R.drawable.smiley_colon_d,
R.drawable.smiley_colon_dollar,R.drawable.smiley_colon_e,
R.drawable.smiley_colon_o,R.drawable.smiley_colon_open,
R.drawable.smiley_colon_p,R.drawable.smiley_colon_pipe,
R.drawable.smiley_colon_s,R.drawable.smiley_colon_slash,
R.drawable.smiley_colon_star,R.drawable.smiley_colon_three,
R.drawable.smiley_colon_x,R.drawable.smiley_greater_than_colon_open,
R.drawable.smiley_kik,R.drawable.smiley_less_than_slash_three,
R.drawable.smiley_less_than_three,R.drawable.smiley_semicolon_close
};

private ImageGetter imageGetter = new ImageGetter() {

@Override
public Drawable getDrawable(String source) {
int id = Integer.parseInt(source);
Drawable draw = getResources().getDrawable(id);
draw.setBounds(0, 0, draw.getIntrinsicWidth(), draw.getIntrinsicHeight());
return draw;
}
};

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        et=(EditText) findViewById(R.id.EditText1);
        expressionButton = (Button) findViewById(R.id.expressionButton);
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.customdialog, null);
        //获取自定义对话框中的GridView
        mGridView  = (GridView) layout.findViewById(R.id.gridview);
        mGridView.setAdapter(new ImageAdapter(MainActivity.this));
        
        //使用快捷键快速出现表情
        et.setOnKeyListener(new EditText.OnKeyListener() {
        
         @Override
         public boolean onKey(View v, int keyCode, KeyEvent event) {
         EditText ev = (EditText) v;
         String s_ev = ev.getText().toString().trim();
         //Log.i(TAG, s_ev);
         //Log.i(TAG, ExpressShortCut.AX_POSITION+"");
         if(s_ev.equals(ExpressShortCut.SYSTEM_EXPRESS_MJ)) {
         et.setText("");
         et.append(Html.fromHtml("<img src='"+face[ExpressShortCut.MJ_POSITION]+"'/>",imageGetter,null));
         }
return false;
         }
});再次在这里谢谢昨天帮忙的帅哥美女们 我爱你们

解决方案 »

  1.   

    就是第一次打/wx出表情 但是表情没删除的话 在打/wx就不行了 牛人们给点高招啊
      

  2.   

    以前看过一点,android中有mutilTextAutoComplete这个属性,可以看下,这里面还有些东西的,我在and pro 2 中看到的
      

  3.   

    android中mutilTextAutoComplete这个属性
      

  4.   

    想问一下楼主 在EditText中插入了表情后 怎么显示出来啊 既有文字又有表情图片 怎么分离显示啊,急啊,在这里先谢谢楼主了 帮帮忙