1
환경 설정에 문제가 있습니다. 나는이 간단한 프로젝트를 만들어 : start.java :기본 레이아웃의 Android 환경 설정
package example.ex;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class start extends Activity {
Intent intent;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void preferences (View view){
intent = new Intent(getApplicationContext(), Preferences.class);
startActivity(intent);
}
}
Preferences.java :
package example.ex;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Preferences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
주요 활동이 환경에 우리가 (버튼을 통해) 이동되는 시작을,입니다. 환경 설정에는 환경 설정 (팝업이있는 목록)이 표시됩니다.
레이아웃 : main.xml에 :
이<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="preferences"
android:onClick="preferences" />
</LinearLayout>
preferenze.xml : 내가 넣어 값
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow>
<TextView
android:text="List Selection:"
android:paddingRight="5px"
/>
<TextView android:id="@+id/list"
/>
</TableRow>
</TableLayout>
이
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="country">
<item>U.S. (United States of America)</item>
<item>Italia (Italy)</item>
</string-array>
<string-array name="codice_paese">
<item>US</item>
<item>IT</item>
</string-array>
</resources>
을 arrays.xml 마지막으로, 나는 환경을 만들었습니다. xml (res에있는 폴더 xml) :
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Simple Preferences">
<ListPreference android:key="list" android:title="Selection Dialog"
android:summary="Click to pop up a list to choose from"
android:entries="@array/country" android:entryValues="@array/codice_paese"
android:dialogTitle="Choose a country" />
</PreferenceCategory>
</PreferenceScreen>
다음 : 메인이 있고 환경 설정 페이지로 이동합니다.
내가 (대신 버튼의) 주요 환경에 직접 넣어 하나 개의 활동
를 사용하고 싶습니다하지만 난 당신이 어떤 제안을하시기 바랍니다 .. 어떤 방법으로 그것을 할 수없는 는? 덕분에 !
따라서 main.xml 및 strings.xml을 적절하게 업데이트하십시오. 나는 그것으로 아주 thourough가 아니었다 그러나 나가 didnt는 당신이 그것의 무엇이든에 관하여 질문이있는 경우에 당신이 그것을 또는 더 이상 필요로하지 않을지도 모르다는 것을 기회에 이것에 시간의 톤을 소요하고 싶다 그래서 저에게 알고있다. 아프다. –