코드에 문제가 없습니다. 도움?메뉴 버튼을 통해 환경 설정이 호출되면 강제 종료 메시지가 표시됩니다.
preferences.xml로
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:title="Gender"
android:summary="Are you male or female?"
android:key="genderPref"
android:defaultValue="male"
android:entries="@array/genderArray"
android:entryValues="@array/genderValues" />
<ListPreference
android:title="Weight"
android:summary="How much do you weigh?"
android:key="weightPref"
android:defaultValue="180"
android:entries="@array/weightArray"
android:entryValues="@array/weightValues" />
</PreferenceScreen>
arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="genderArray">
<item>Male</item>
<item>Female</item>
</string-array>
<string-array name="genderValues">
<item>male</item>
<item>female</item>
</string-array>
<string-array name="weightArray">
<item>120</item>
<item>150</item>
<item>180</item>
<item>210</item>
<item>240</item>
<item>270</item>
</string-array>
<string-array name="weightValues">
<item>120</item>
<item>150</item>
<item>180</item>
<item>210</item>
<item>240</item>
<item>270</item>
</string-array>
</resources>
Preferences.java :
package com.dantoth.drinkingbuddy;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
};
}
butts.xml (이것은 꽁초 이유 나도 몰라하지만 난 익숙해했습니다 이제 메뉴 버튼을 설정하기 만하면됩니다.)
DrinkingBuddy.java 내<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:title="Settings"
android:icon="@drawable/ic_menu_settings" />
<item android:id="@+id/archive"
android:title="Archive"
android:icon="@drawable/ic_menu_archive" />
<item android:id="@+id/new_session"
android:title="New Session"
android:icon="@drawable/ic_menu_new" />
<item android:id="@+id/about"
android:title="About"
android:icon="@drawable/ic_menu_about" />
</menu>
: 그것 뿐이다
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.settings:
startActivity(new Intent(this, Preferences.class));
return true;
case R.id.archive: Toast.makeText(this, "Expect to see your old drinking sessions here.", Toast.LENGTH_LONG).show();
return true;
//ETC.
} return false;
. 전화기의 메뉴 버튼을 눌러 내가 만든 메뉴 항목을 볼 수 있지만 "설정"(r.id.settings)을 클릭하면 FC가 표시됩니다. 이걸 작동 시키려면 매니페스트/다른 것에 무엇인가해야합니까?
LogCat에 어떤 종류의 오류 메시지가 있어야합니다. FC 문제에 게시하면 대개 도움이됩니다. – jqpubliq