1.I有TextView
ID为textView1
Android的 - 我需要一些澄清
我。
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hellow World");
或而不产生电视,
((TextView) findViewById(R.id.textView1)).setText("Hellow World");
II。
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hellow World");
tv.setTextSize(someValue);
tv.setTag("title");
或
((TextView) findViewById(R.id.textView1)).setText("Hellow World");
((TextView) findViewById(R.id.textView1)).setTextSize(someValue);
((TextView) findViewById(R.id.textView1)).setTag("title");
其做法是在两种情况下好,有什么区别。
2.similerly我有一个String childName
这就需要从3种方法
II可以创建一个场变量childName
,并且可以从所有3种方法
通过每个ii.passing可变访问方法等,
setChildFragment(childName);
在
public setChildFragment(String childName){
.
.
.
setChildView(childName);
}
和,
在TextView中public setChildView(String childName){
.
.
.
setChildTitle(childName);
}
最后,
public setChildTitle(String childName){
((TextView) findViewById(R.id.title)).setText("Hellow World");
}
哪种方法更好,为什么!!!
谢谢提前
有调用'findViewById' –
的开销为什么不能'setChildFragment'只是调用相当于((TextView)findViewById(R.id.title))。setText(“Hellow World”);'直接?注意:您从未使用'childName' –
'findViewById()'是非常昂贵的操作,并且随着它的布局成本的复杂性增加。不必要地使用它可能会在您的应用程序中引起打嗝。 –