Java 在內(nèi)部類中訪問變量需要宣布為最終
如果您不想使其最終確定,則始終可以將其設為全局變量。
解決方法因此標題說明了一切。我的內(nèi)出現(xiàn)編譯錯誤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. 注冊賬戶文字不能左右分離2. JavaScript事件3. html5 - ElementUI table中el-table-column怎么設置百分比顯示。4. javascript - table列過多,有什么插件可以提供列排序和選擇顯示列的功能5. python - 使用readlines()方法讀取文件內(nèi)容后,再用for循環(huán)遍歷文件與變量匹配時出現(xiàn)疑難?6. javascript - ES6標準入門中l(wèi)et命令提到的for循環(huán)打印i是10,如果不用let怎么替換?7. showpassword里的this 是什么意思?代表哪個元素8. 對mysql某個字段監(jiān)控的功能9. python - 為什么正常輸出中文沒有亂碼,zip函數(shù)之后出現(xiàn)中文編程unicode編碼的問題,我是遍歷輸出的啊。10. html - vue項目中用到了elementUI問題
