Java 我是否应该将UI对象声明为";“最后的”;能够访问它吗?
我有以下情况:Java 我是否应该将UI对象声明为";“最后的”;能够访问它吗?,java,android,variables,inheritance,Java,Android,Variables,Inheritance,我有以下情况: public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.createcharacter); //Referenciando Items do Layout Button voltar = (Button) findViewById(R.id.voltar);
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.createcharacter);
//Referenciando Items do Layout
Button voltar = (Button) findViewById(R.id.voltar);
Button criar = (Button) findViewById(R.id.criar);
final TextView nome = (TextView) findViewById(R.id.nome);
...........
criar.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
if(portraitSelected == false)
{
Toast.makeText(CreateCharacter.this, "Selecione um Avatar", Toast.LENGTH_SHORT).show();
Toast.makeText(CreateCharacter.this, nome.getText(), Toast.LENGTH_SHORT).show();
}
else if(nome.getText() == null)
{
Toast.makeText(CreateCharacter.this, "Digite um Nome!", Toast.LENGTH_SHORT).show();
}
.......
为了进入
else if(nome.getText()==null)
我需要在onCreate()方法的开头声明它为FINAL,可以吗?
如果不是,我应该怎么做?您需要将其声明为
final
,以便可以在匿名视图中访问它。OnClickListener
类。这是的限制,但使参考成为最终参考
不应该有任何重大问题
简短版本:很好。谢谢!我在大学里做过一些java编程,但在安卓系统中,我有点笨,现在正在学习如何工作。所以我将宣布所有这些都是最终版本,问题是在android开发指南中它们并不是最终版本。谢谢