如何在java中共享textView?
您好,我正在尝试共享保存在xml页面的textView中的文本。下面是我目前拥有的共享一组文本的代码,但我想知道是否可以在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
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);