我希望用户能够分享从一组文本中随机查看文本的内容,但这似乎非常复杂。我试图寻找答案,但每个人都在谈论共享图像。
这是我的Java代码:
public class Second extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
final TextView generatedtxt = (TextView) findViewById(R.id.generatedtxt);
Typeface custom_font = Typeface.createFromAsset(getAssets (), "fonts/1.ttf");
generatedtxt.setTypeface(custom_font);
Button generatebtn = (Button) findViewById(R.id.generatebtn);
final String[] gn = {"text1", "text2", "text3", "text4", "text5"};
generatebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int rando = (int) (Math.random() *5);
generatedtxt.setText(gn[rando]);
}
});
}
}
这是我的 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:background="@drawable/bg2"
android:paddingTop="@dimen/activity_vertical_margin" >
<Button
android:id="@+id/generatebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/sharebtn"
android:text="@string/generatebtn" />
<Button
android:id="@+id/sharebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/sharebtn" />
<TextView
android:id="@+id/generatedtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/generatebtn"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="@string/gt"
android:textSize="40sp" />
有人能帮助我吗?