Java 在内部类中访问变量。需要宣布为最终
如果您不想使其最终确定,则始终可以将其设为全局变量。
解决方法因此标题说明了一切。我的内出现编译错误onClick。
这是代码。
public class fieldsActivity extends Activity {Button addSiteButton;Button cancelButton;Button signInButton;/** * Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // to create a custom title bar for activity window requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.fields); // use custom layout title bar getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.topbar); Pager adapter = new Pager(); ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager); mPager.setAdapter(adapter); mPager.setCurrentItem(1); addSiteButton = (Button) findViewById(R.id.addSiteButton); addSiteButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) { mPager.setCurrentItem(2,true); //Compilation error happens here.} }); cancelButton = (Button) findViewById(R.id.cancel_button); signInButton = (Button) findViewById(R.id.sign_in_button);}
相关文章:
1. PHP类中的$this2. python - Django Admin创建不关联任何model的自定义页面3. javascript - h5分享链接到qq或者微信时有一个缩略图还有一些说明文字,这个要怎么去修改里面的图片和内容?4. javascript 如何下载一个excel文件 ?5. 谁有mysql5.7安装的详细教程6. mysql - 看这条sql有可能被注入吗7. python - Django操作数据库遇到问题,无法查询更新后的数据8. 请问是对象还是数组9. android - 第三方App调用高德地图,总是直接进入到导航页面,有没有办法进入首页?10. python2.7 - Python安装模组不成功
