I cant't set a text view in my splash screen, Using the below code
override fun onCreate(savedInstanceState: Bundle?) {
setContentView(R.layout.activity_main);
val textView = findViewById<TextView>(R.id.rand)
val thoughts = arrayOf("Trading Made Easy!","Where Smart People Trade","For Smart Traders Like You!")
fun getRandomQuote(): String {
val randomValue = kotlin.random.Random.nextInt(thoughts.size-1)
return thoughts[randomValue]
}
var thought = getRandomQuote().toString()
textView.setText(thought)
}
the splash screen just shows the default text in the .xml file ,
<TextView
android:id="@ id/rand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The Future Of Trading"
android:layout_below="@ id/app_logo"
android:layout_marginTop="0dp"
android:textSize="18sp"
android:textColor="@color/colorBlack"
android:textStyle="bold"
android:layout_centerHorizontal="true" />
CodePudding user response:
In your code, you havent called super.oncreate
.
It might throw SuperNotCalledException
.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Your logic
}
CodePudding user response:
In your code remove this part :
thought = getRandomQuote().toString()
textView.setText(thought)
And write this in place of it
textView.text = getRandomQuote()