本文介绍了变量是内部类中访问。需要声明的最终的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,标题说明了一切。 我得到我的onClick
的内部编译错误我敢肯定,这是一个非常简单的解决,但我不完全知道如何把它写。我仍然在android开发的早期阶段,所以请原谅我的小白的烦躁。 :)
这里的code。
公共类fieldsActivity延伸活动{ 按钮addSiteButton; 按钮cancelButton; 按钮signInButton; / ** *第一次创建活动时调用。 * / @覆盖 公共无效的onCreate(包savedInstanceState){ super.onCreate(savedInstanceState); //创建为活动窗口自定义标题栏 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 的setContentView(R.layout.fields); //使用自定义布局标题栏 。getWindow()setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.topbar); 寻呼机适配器=新寻呼机(); ViewPager mPager =(ViewPager)findViewById(R.id.fieldspager); mPager.setAdapter(适配器); mPager.setCurrentItem(1); addSiteButton =(按钮)findViewById(R.id.addSiteButton); addSiteButton.setOnClickListener(新View.OnClickListener(){ @覆盖 公共无效的onClick(视图v){ mPager.setCurrentItem(2,真); //编译错误发生在这里。 } }); cancelButton =(按钮)findViewById(R.id.cancel_button); signInButton =(按钮)findViewById(R.id.sign_in_button); }解决方案
该错误说明了一切,改变:
ViewPager mPager =(ViewPager)findViewById(R.id.fieldspager);
到
最后ViewPager mPager =(ViewPager)findViewById(R.id.fieldspager);So the title says it all. I'm getting a compilation error inside of my onClick
I'm sure this is a really simple fix, but I'm not exactly sure how to write it. I'm still in the early stages of android development, so pardon my noob-ness. :)
Here's the code.
public class fieldsActivity extends Activity { Button addSiteButton; Button cancelButton; Button signInButton; /** * Called when the activity is first created. */ @Override public 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() { @Override public 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); }解决方案
The error says it all, change:
ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager);to
final ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager);
更多推荐
变量是内部类中访问。需要声明的最终
发布评论