开发者

Complete newbie question, textview handle not recognizing

开发者 https://www.devze.com 2023-02-24 23:54 出处:网络
My previous coding experience has been with python, and only scripts related to data stream processing.

My previous coding experience has been with python, and only scripts related to data stream processing.

I'm getting a compile error when referencing a textview handle

To boil some code down: during onCreate(), calls a function setupHandles()

public void setupHandles(){
    //initialize internal controls to text labels
     TextView tvmoney = (TextView) findViewById(R.id.moneyText);
     TextView tvsave = (TextView) findViewById(R.id.savingsText);
     ..... etc etc many more handles

now in a part of code from onResume(), I try to do, for example:

tvmoney.setText(("Money: $" + "foo" + "bar"));

Its saying that the tvm开发者_如何学Pythononey can't be resolved. Why is this? The setupHandles has to have run, onCreate, and it is public... But if I put the line 3 in onResume, the handle works. How can I get it to either pass the handles along, or make it truly public?


The reference named tvmoney is obtained and only available in method setupHandles(). Once the execution of setupHandles() finishes, tvmoney is gone.

To solve this, just set tvmoney as a global variable (outside of any method)

0

精彩评论

暂无评论...
验证码 换一张
取 消