Correct way to refer to a view in Android What is the correct way of referring to a view (a) or (b).?

(a).

TextView textView = (TextView) rootView.findViewById(R.id.text);
textView.setText("Some Text");


(b).

((TextView) rootView.findViewById(R.id.text)).setText("Some Text");


I sometimes use the combination of both in my code. Will that affect my structure negatively in any way?

Is there any disadvantage / advantages when using any of those?
The first is a sequence of method calls, the second is a method call chain. They are equivalent, so both are correct.

Which way is better really depends on the rest of your code.
For example, instead of this:

((TextView) rootView.findViewById(R.id.text)).setText("Some Text");
((TextView) rootView.findViewById(R.id.text)).append("more text");
((TextView) rootView.findViewById(R.id.text)).setOnClickListener(...);


This is clearly better:

TextView textView = (TextView) rootView.findViewById(R.id.text);
textView.setText("Some Text");
textView.append("more text");
textView.setOnClickListener(...);


It's better, because this does only one lookup in rootView, and it's also more compact.

On the other hand, if you only use the TextView once, then the chained call version is better, because you won't pollute your local scope with a variable you only use once, and it's more compact.

Sometimes I split chained calls for debugging purposes:
it can be hard to see which step failed in a long chain,
and easier to follow the execution step by step.