在TextView的Andr​​oid中选定的文本长preSS [英] long press on selected text in textview in android

查看:166
本文介绍了在TextView的Andr​​oid中选定的文本长preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我有一个文本视图和它的一些文字。我想用户可以看到工具提示框的话的含义当上了字,他长preSS。我的问题是,我不知道如何实现长时间preSS在words.Can一些身体帮我?

In my android app, I have a text view and some text in it. I want that user can see the meaning of the words in a tool tip box when he long press on the word . My problem is that I don’t know how to implement long press in the words.Can some body help me?

对不起,我英文不好。

Sorry for my poor English.

推荐答案

使用下面的code:

tv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            return false;
        }
});

和进口:

import android.view.View.OnLongClickListener;

如果你想点击只是为某些部分来看,你需要 ClickableSpan 。从<副本code href="http://stackoverflow.com/questions/10696986/how-to-set-the-part-of-the-text-view-is-clickable">this链接。

if you want Click just for some part Of View you need ClickableSpan. copy code from this link.

    SpannableString ss = new SpannableString("Android is a Software stack");
    //ss.setSpan(new StyleSpan(Typeface.ITALIC), 22, 27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ClickableSpan clickableSpan = new ClickableSpan() {
        @Override
        public void onClick(View textView) {
            startActivity(new Intent(MyActivity.this, NextActivity.class));
        }
    };
    ss.setSpan(clickableSpan, 22, 27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    TextView textView = (TextView) findViewById(R.id.hello);
    textView.setText(ss);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

这篇关于在TextView的Andr​​oid中选定的文本长preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆