I have a dilemma. I've created this random sentence generator script for java. And I want to show "sentence" in a text view like you would print it out to the system on line 25 in android studio.
Here's my Random Sentence Generator Code
package com.tech.littlest.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Random;
public class Activity2 extends AppCompatActivity {
final static int NO_DEDICATED_ARRAYS = 12; // This number is equal to the number of arrays in a string NOTE: This number MUST be constant across all strings
final static int NO_OUTPUT_SENTENCES = 1; // How many sentences generated and displayed for the user
final static String SPACER = " "; // Inputs a " " character (Space) into the display
final static String PERIOD = ".";
static Random r = new Random();
public static void main( String args[] ){
String proposition_user[] = { "You should build and invention that", "You should build a robot that", "You should create a whatchamacallit that", "There should be a device that", "Create a futuristic thing that", "Make a thing that", "Make something cool that", "I don't recall there being a thing that", "Create a sick thing that", "Devise a plan to create an object that", "I want a thing that", "If I just had an thingamajig that", "Create a thingimajig that"};
String plural_noun[] = { "children", "chickens", "the ocean", "cars", "apples", "houses", "water", "buildings", "people", "your friends", "farms", "the human race" };
String verb[] = { "directs you to", "drives on", "manages", "develops", "makes","eats", "helps", "relocates", "fixes", "feeds", "runs on", "washes" };
String sentence;
for (int i = 0; i < NO_OUTPUT_SENTENCES; i++){
sentence = proposition_user[rand()];
char c = sentence.charAt(0);
sentence = sentence.replace( c, Character.toUpperCase(c) );
sentence += SPACER;
sentence += (verb[rand()]);
sentence += (SPACER + plural_noun[rand()]);
sentence += PERIOD;
sentence += "";
System.out.println(sentence);
}
}
static int rand(){
int ri = r.nextInt() % NO_DEDICATED_ARRAYS;
if ( ri < 0 )
ri += NO_DEDICATED_ARRAYS;
return ri;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
}
}
My XML file with my textview
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tech.littlest.myapplication.Activity2">
<TextView
android:id="@+id/mytextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Thanks!