Reputation: 3357
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.lbSightName).setText("Some Text");
Not possible?
Upvotes: 0
Views: 982
Reputation: 44063
Sure
((TextView) findViewById(R.id.lbSightName)).setText("Some Text");
Upvotes: 2
Reputation: 2102
((TextView)findViewById(R.id.lbSightName)).setText("Some thingy");
Adding one more set of parenthesis does the trick
Upvotes: 1
Reputation: 15792
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");
Upvotes: 5
Reputation: 17888
((TextView) findViewById(R.id.lbSightName)).setText("Some Text");
Upvotes: 4
Reputation: 351
((TextView) findViewById(R.id.lbSightName)).setText("Some Text");
Just add braces.
Upvotes: 2
Reputation: 14766
With one more set of parenthesis it should be possible:
((TextView)findViewById(R.id.lbSightName)).setText("Some Text");
Upvotes: 2