[英]Can't I add a new Java class while using an activity template in Android studio?
[英]New to android studio and java, stuck with an error I can't fix
我正在使用本教程 ,但遇到了麻煩。
我在openSettings();
上收到錯誤openSettings();
和openSearch();
該程序說
無法解決的方法
誰能告訴我我做錯了什么?
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
openSetting();
return true;
} else if (item.getItemId() == R.id.action_search) {
openSearch();
return true;
}
return super.onOptionsItemSelected(item);
}
如果我不得不猜測,我認為您是從下面的示例開始的: https : //github.com/arun-gupta/android-samples/blob/master/HelloWorldProject/HelloWorld/src/main/java/name/arungupta/android/ helloworld / MainActivity.java
為了解決您的問題,您需要在類中添加以下兩個方法:
private void openSettings() {
Intent intent = new Intent(this, SettingsActivity.class);
intent.putExtra(SETTINGS_MESSAGE, "Settings");
startActivity(intent);
}
private void openSearch() {
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SEARCH_MESSAGE, "Search Now");
startActivity(intent);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.