Java: type casting question
Is there any way to do this in a single line:
TextView tv = (TextView) findViewById(R.id.lbSightName);
tv.setText("Some Text");
I would like to do away declaring the intermediary tv, like so:
(TextView) findViewById(R.id.lbSightN开发者_Python百科ame).setText("Some Text");
Not possible?
You can, but it isn't best practice
((TextView) findViewById(R.id.lbSightName)).setText("Some Text");
TextView.class.cast(findViewById(R.id.lbSightName).setText("Some Text");
((TextView) findViewById(R.id.lbSightName)).setText("Some Text");
With one more set of parenthesis it should be possible:
((TextView)findViewById(R.id.lbSightName)).setText("Some Text");
((TextView) findViewById(R.id.lbSightName)).setText("Some Text");
Just add braces.
Sure
((TextView) findViewById(R.id.lbSightName)).setText("Some Text");
((TextView)findViewById(R.id.lbSightName)).setText("Some thingy");
Adding one more set of parenthesis does the trick
精彩评论