Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中共享textView?_Java_Android - Fatal编程技术网

如何在java中共享textView?

如何在java中共享textView?,java,android,Java,Android,您好,我正在尝试共享保存在xml页面的textView中的文本。下面是我目前拥有的共享一组文本的代码,但我想知道是否可以在textView中与文本一起共享一段文本 public void share (View view) { Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIn

您好,我正在尝试共享保存在xml页面的textView中的文本。下面是我目前拥有的共享一组文本的代码,但我想知道是否可以在textView中与文本一起共享一段文本

    public void share (View view)
        {                       
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
        sharingIntent.setType("text/plain");
        String shareBody = "Ive just completed the quiz with the score";
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(sharingIntent, "Share via"));
        }
下面是我试图共享的xml工作表中的textView

<TextView
            android:id="@+id/textResult"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.08"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" 
            android:layout_marginLeft="100dp"/>

文本视图获取值

String str=textResult.getText().toString()
通过它

 textResult=(TextView)findViewById(R.id.RateText);
 share(textResult);


我认为您要查找的(“…文本片段以及文本视图中的文本…”)是:

其中,
tv
是您将传递给共享方法的
TextView
,而不是
视图

i、 e更改:

public void share (View view)
public void share (TextView tv)
至:

public void share (View view)
public void share (TextView tv)

tv
应通过以下方式获得:

tv = (TextView) findViewById(R.id.textResult);

谢谢你的回复,我已经输入了上面的代码,但是当我运行应用程序时,当我尝试分享时它崩溃了,有什么想法吗?我的第一个猜测是,你需要在清单中获得一些权限。您在控制台中遇到的错误是什么?
tv = (TextView) findViewById(R.id.textResult);