android中未打开的活动
我刚刚开始开发android应用程序 因此,我在eclipse中制作了一个以android 10为基础的应用程序(姜饼) 然后我编辑了我的主要活动(main.java)以显示一个包含两个选项的菜单a)设置B)关于 然后我在/res/xml/settings.xml创建了一个资源,然后制作了Prefs.java,它使用addPreferencesFromResource()方法 但是当我点击设置时,我什么也看不到。。 我还在我的应用程序的Android清单中定义了活动 这是我的密码: //Prefs.javaandroid中未打开的活动,android,android-activity,Android,Android Activity,我刚刚开始开发android应用程序 因此,我在eclipse中制作了一个以android 10为基础的应用程序(姜饼) 然后我编辑了我的主要活动(main.java)以显示一个包含两个选项的菜单a)设置B)关于 然后我在/res/xml/settings.xml创建了一个资源,然后制作了Prefs.java,它使用addPreferencesFromResource()方法 但是当我点击设置时,我什么也看不到。。 我还在我的应用程序的Android清单中定义了活动 这是我的密码: //Pref
package com.mhrsolanki2020.thecaller;
import android.preference.PreferenceActivity;
import android.os.Bundle;
public class Prefs extends PreferenceActivity {
protected void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
addPreferencesFromResource(R.xml.settings);
}
}
//Main.java
package com.mhrsolanki2020.thecaller;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSecelted(MenuItem item){
switch(item.getItemId()){
case R.id.action_settings:
startActivity(new Intent(this,Prefs.class));
return true;
}
return false;
}
}
//安卓清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mhrsolanki2020.thecaller"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.mhrsolanki2020.thecaller.Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.mhrsolanki2020.thecaller.Prefs"
android:label="@string/prefs_label"> </activity> </application>
</manifest>
///res/xml/settings.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:defaultValue="true"
android:title="@string/activation"
android:summary="@string/activatoinSummary"/>
</PreferenceScreen>
///menu/main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"/>
<item
android:id="@+id/action_about"
android:orderInCategory="101"
android:title="@string/action_about"/>
</menu>
您有一个输入错误:
public boolean onOptionsItemSecelted(MenuItem item){ // <-- typo onOptionsItemSelected
switch(item.getItemId()){
case R.id.action_settings:
startActivity(new Intent(this,Prefs.class));
return true;
}
return false;
}
public boolean-onoptionsItemsSecelted(MenuItem-item){/您有一个输入错误:
public boolean onOptionsItemSecelted(MenuItem item){ // <-- typo onOptionsItemSelected
switch(item.getItemId()){
case R.id.action_settings:
startActivity(new Intent(this,Prefs.class));
return true;
}
return false;
}
public boolean onoptionsItemsSecelted(MenuItem项){//你确定要输入OnOptions ItemsSecelted吗?你能设置断点并查看吗?OnOptions ItemsSecelted
-typo-OnOptions ItemSelected
你确定要输入OnOptions ItemsSecelted吗?你能设置断点并查看吗?OnOptions ItemsSecelted
-typo-OnOptions ItemSelected
嘿,谢谢这是一个可怕的错误。Eclipse不会识别这样的打字错误??它应该给我一个错误,对吗?因为您没有使用覆盖
,Eclipse会将其视为您命名的方法。这是完全合法的,但当然不会被调用。添加覆盖
,Eclipse会告诉您没有这样的方法可以使用覆盖。谢谢提醒:)嘿,谢谢..那是一个可怕的错误..Eclipse不识别这样的打字错误??它应该给我一个错误,对吗?因为你没有使用override
,Eclipse会将它视为你命名的方法。它完全合法,但当然不会被调用。添加override
和Eclipse会告诉您没有这种方法可以覆盖。谢谢提醒:)