2 qq 16980459 qq_16980459 于 2016.04.09 18:35 提问

android新手有段代码没看懂,help me please!小米便签的源码
@Override
protected void onCreateContextMenu(ContextMenu menu) {
    if (getText() instanceof Spanned) {
        int selStart = getSelectionStart();
        int selEnd = getSelectionEnd();

        int min = Math.min(selStart, selEnd);
        int max = Math.max(selStart, selEnd);

        final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
        if (urls.length == 1) {
            int defaultResId = 0;
            for(String schema: sSchemaActionResMap.keySet()) {
                if(urls[0].getURL().indexOf(schema) >= 0) {
                    defaultResId = sSchemaActionResMap.get(schema);
                    break;
                }
            }

            if (defaultResId == 0) {
                defaultResId = R.string.note_link_other;
            }

            menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
                    new OnMenuItemClickListener() {
                        public boolean onMenuItemClick(MenuItem item) {
                            // goto a new intent
                            urls[0].onClick(NoteEditText.this);
                            return true;
                        }
                    });
        }
    }
    super.onCreateContextMenu(menu);
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!