[Solved] How do I show a result from Random in a textview?


You have to add a TextView to display the result.

Step 1. Adding ID to TextView, in the XML file.

 <TextView
        android:id="@+id/myId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        .... />

Step 2. Finding TextView using ID, under onCreate method:

@Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView myTextView = (TextView) findViewById(R.id.myId);
    }

Step 3. Set the text with setText()

myTextView.setText(n+" "); //setText only accepts a String

solved How do I show a result from Random in a textview?