我在做一个小应用,要显示一篇文章,在触摸屏上点击文章中的某一个字的时候,这个字可以作为参数,通过startActivity(intent)启动并传给下一个Layout,下一个Layout处理这个字的相关问题。
     做过一些实验,效果不好,请给个思路或方法,谢谢。
     另:文档大的时候,还需要垂直滚动条。

解决方案 »

  1.   

       Bundle类用作携带数据,它类似于Map,用于存放key-value名值对形式的值。相对于Map,它提供了各种常用类型的putXxx()/getXxx()方法,如:putString()/getString()和putInt()/getInt(),putXxx()用于往Bundle对象放入数据,getXxx()方法用于从Bundle对象里获取数据。Bundle的内部实际上是使用了HashMap<String, Object>类型的变量来存放putXxx()方法放入的值:
    public final class Bundle implements Parcelable, Cloneable {
                ......
     Map<String, Object> mMap;
     public Bundle() {
           mMap = new HashMap<String, Object>();
            ......
     }
     public void putString(String key, String value) {
          mMap.put(key, value);
     }
    public String getString(String key) {
           Object o = mMap.get(key);
            return (String) o;
            ........//类型转换失败后会返回null,这里省略了类型转换失败后的处理代码
    }
    }
    在调用Bundle对象的getXxx()方法时,方法内部会从该变量中获取数据,然后对数据进行类型转换,转换成什么类型由方法的Xxx决定,getXxx()方法会把转换后的值返回
      

  2.   

    现在我遇到的不是传参数的问题,是怎么得到被点击的是哪个字的问题。传参数很容易,是android的标准用法。
      

  3.   

     我觉得很简单 TextView控件中  添加OnClickListener()  并实现 View.OnClickListener()中的Click()
    就是了吗
      

  4.   

    我觉得很简单 TextView控件中 添加setOnClickListener() 并实现 View.OnClickListener()中的Click()
    就是了吗
      

  5.   

    如果存在Activity之间的跳转,那就用Bundle吧。
      

  6.   


    对TEXtView监听在onclick取得他的值,如果跳转到下一个Activity就把取到的值放到Bundle里
      

  7.   

        抱歉,我没有说清楚,我需要知道被点中的具体是哪个字。Activity之间使用Bundle传输数据是一个标准用法,只要按句法写代码就可以了。
        再重新描述一下我的问题:比如我有一段文字,我要传递的是点中了哪一个字。比如前面的这段文字,点中的是:“我”,还是“有”,或者是“文”。新启动的那个Layout要得到被点的那个确切的文字。
        下面这段程序不能满足我的需要。它传递的是“比如我有一段文字,我要传递的是点中了哪一个字。”这一段文字,而我不知道使用者具体点的是那一个字。
            tv = (TextView)findViewById(R.id.TextView02); //获得TextView对象的引用
            tv.setMovementMethod(ScrollingMovementMethod.getInstance());
            tv.setOnClickListener(new OnClickListener(){
             public void onClick(View v) {
             String Mytext=tv.getText().toString();
             Bundle Mydata=new Bundle();
             Mydata.putString("Mytext", Mytext);
    // 实例化组件名
    ComponentName cn = new ComponentName(namecard.this, "com.Mytext.SecondLayout");
    // 实例化Intent
            Intent intent = new Intent();
            // 为Intent设置组件名称属性
            intent.setComponent(cn);
            intent.putExtras(Mydata);
            // 启动Activity
            startActivity(intent);
    }
            
            });
    我只想知道,使用者在看一篇我显示的文档时,具体点击了哪一个字。谢谢。
      

  8.   

    textview里好像只有Linkify才有链接功能楼主好好看下Doc。应该能找到方法了。。
    public static final void addLinks (TextView text, Pattern p, String scheme, Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter)
    Since: API Level 1Applies a regex to the text of a TextView turning the matches into links. If links are found then UrlSpans are applied to the link text match areas, and the movement method for the text is changed to LinkMovementMethod.
    Parameters
    text  TextView whose text is to be ed-up with links
    p  Regex pattern to be used for finding links
    scheme  Url scheme string (eg http:// to be prepended to the url of links that do not have a scheme specified in the link text
    matchFilter  The filter that is used to allow the client code additional control over which pattern matches are to be converted into links. 
      

  9.   

    感谢ameyume,你说的方法我也想过,不过如果文档很大,有垂直滚动条的话,算起来就很麻烦了,最主要的是怕不稳定,还要有大量的测试,还一直没有测试。哪位高手给一个方法可以的实现这个功能,原理上就很稳定,多谢了。另:我显示的文档不需要编辑,只需要对用户点中的字进行解释。
      

  10.   

    只是一个字的话,那就一个字一个textview了,
      

  11.   

    一共就几十个字,不超过一百个,点击每一个字都要有相应的解释。一直没有好的方法,我准备在TableLayout下添加多个TextView试试了。
      

  12.   

    哈,楼上的各位。可能没用过。你会写html吗?那你可以试试了。我给你一个建议:
    t3.setText(Html.fromHtml(
                    "<b>text3:</b>  Text with a " +
                    "<a href=\"http://www.google.com\">link</a> " +
                    "created in the Java source code using HTML."));
            t3.setMovementMethod(LinkMovementMethod.getInstance());
    你可以参考这个来试试。这样可以把你想要设置的写成link了。然后可以跳转activity了。跳转应该会吧?
    嘿。看来这个方法。很多人都不知道呀。希望很多人都看到
      

  13.   

         
           几十个字的话,要做几十个link,还要动态的生成,比较麻烦了。我要用同一个Activity处理被点中的那个字,而不是调用不同的Activity。f8376904110的方法好像不能用。
      

  14.   

    使用GridText貌似可以解决。结贴了。