我刚开始使用Android的发展,我被困在此:如何从静态上下文中引用非静态方法'findViewById'?
static Handler h = new Handler()
{
@Override
public void handleMessage(Message msg) {
TextView buttonmain = (TextView)findViewById(R.id.buttonmainid);
if(buttonmain.getText()=="Text1")
buttonmain.setText("Text2");
else
buttonmain.setText("Text1");
}
};
这给有关findViewById的静态上下文内访问()方法的错误。
为什么'Handler'必须是静态的? –
你为什么需要处理程序? – Blackbelt
防止内存泄漏。 @ mr.icetea – fatehfox