Skip to content Skip to sidebar Skip to footer

Java/XML - Change TextView

Can someone explain me why this code doesn't work? I want to change the text of the textview with Java code but nothing changes. package com.example.gethtml; import android.app.Ac

Solution 1:

Code to change the textview's text through java code should contain at least one TextView object to start with. I can not see that in your code. But I am writing below a sample code for that.

setContentView(R.layout.activity_main);
TextView txtView = (TextView) findViewById(R.id.txtview);
txtView.setText("This is changed text");

Your activity_main.xml should contain TextView defined with id you are referring. Hope it helps.


Post a Comment for "Java/XML - Change TextView"