1

i have declared a TextView in MainActivity, and i want to update it (write something else or update a value) in another class. for example in Main Activity I have

value = (TextView) findViewById(R.id.value_view);

How can I access this TextView in another class and update the value ?

Mischiefz
  • 127
  • 16
james3
  • 21
  • 5
  • 1
    Use an `interface` if logic calls for it. Or look into this: http://stackoverflow.com/questions/10996479/how-to-update-a-textview-of-an-activity-from-another-class – denvercoder9 Nov 24 '16 at 17:59
  • Did you try passing the context reference as in this question, http://stackoverflow.com/questions/10996479/how-to-update-a-textview-of-an-activity-from-another-class? – Dania Nov 24 '16 at 18:12

1 Answers1

2

You need to create TextView object dynamically and give reference of previously created TextView to it.

TextView txt;
txt=(TextView)FindViewById(R.id.text_view);
txt.setText("New Content");
Mischiefz
  • 127
  • 16
Avdhut K
  • 74
  • 1
  • 13