How do I set the text of an Android TextView from Java?

Make sure to initialize textview

TextView tvName = (TextView) findViewById(R.id.tv_name);
tvName.setText(getResources().getString(R.string.name_xml));

Also make sure in your setContentView xml the tv_name is declared as TextView in the layout.

Leave a Comment