Home > Blockchain >  How to edit a layout of an activity using java in Android
How to edit a layout of an activity using java in Android

Time:06-06

For example, there is a MainActivity.java and a activity_main.xml. Now I have a java tool class called SetText.java . How can I set text to a TextView in activity_main.xml?

CodePudding user response:

on create: Textview Settime = findViewById(R.id.txtentertime); Settime.setText(")

CodePudding user response:

ToolClass:   

public static void setText(TextView tv,String msg){
   tv.setText(msg)
}

Use it:

TextView tv = (TextView) findViewById(R.id.textview)
ToolClass.setText(tv,"somethings")
  • Related