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 - Web開發 - POI導出帶有下拉框的Excel和解決下拉中數組過多而產生的異常2. Python做掃描,發包速度實在是太慢了,有優化的方案嗎?3. javascript - 關于定時器 與 防止連續點擊 問題4. objective-c - ios百度地圖定位問題5. java - 微信退款,公賬號向個人轉賬SSL驗證失敗6. python - 使用xlsxwriter寫入Excel, 只能寫入65536 無法繼續寫入.7. python - flask如何創建中文列名的數據表8. java - 安卓接入微信登錄,onCreate不會執行9. 微信開放平臺 - Android調用微信分享不顯示10. python - mysql 如何設置通用型字段? 比如像mongodb那樣
