开发者

Complete newbie question, textview handle not recognizing

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜