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. Java反射問題:為什么android.os.Message的recycleUnchecked方法不能通過反射獲取到?2. 如何分別在Windows下用Winform項模板+C#,在MacOSX下用Cocos Application項目模板+Objective-C實現一個制作游戲的空的黑窗口?3. html5和Flash對抗是什么情況?4. php如何獲取訪問者路由器的mac地址5. javascript - 在 vue里面用import引入js文件,結果為undefined6. javascript - ...mapGetters和...mapState獲取到的state,怎么拿來在methods中操作?7. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現8. python - linux怎么在每天的凌晨2點執行一次這個log.py文件9. javascript - vue-resource中如何設置全局的timeout?10. 前端 - node vue webpack項目文件結構
