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. node.js - 在vuejs-templates/webpack中dev-server.js里為什么要exports readyPromise?2. mysql優化 - 關于mysql分區3. html5 - 如何實現帶陰影的不規則容器?4. javascript - 循環嵌套多個promise應該如何實現?5. python - 管道符和ssh傳文件6. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應7. objective-c - iOS開發支付寶和微信支付完成為什么跳轉到了之前開發的一個app?8. javascript - 為什么這個點擊事件需要點擊兩次才有效果9. javascript - ionic2 input autofocus 電腦成功,iOS手機鍵盤不彈出10. vue.js - vue 打包后 nginx 服務端API請求跨域問題無法解決。
