0
I'm just trying to update TextView (@id/pref_gender_textView) in the "gender.xml" where gender.xml is defined in preference.xml. I'd like to update the TextView from MyPreferenceFragment.java
如何從MyPreferenceFragment.java更新TextView genderTextView?
非常感謝您提前!如何更新不同佈局的TextView
gender.xml:
<LinearLayout style="@style/PrefHorizontalLayout2" android:theme="@style/AppTheme"> <TextView style="@style/PrefTextTitle2" android:text="@string/pref_gender"/> <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/pref_gender_textView" </LinearLayout>
- preference.xml樣子:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="lp_gender"
android:entries="@array/array_lp_gender"
android:entryValues="@array/array_lp_gender_values"
android:title="@string/str_lp_android_choice_gender"
android:layout="@layout/gender"/>
</PreferenceScreen>
現在,我想訪問「genderTextView」從某處「MyPreferenceFragment.java」
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MyPreferenceFragment extends PreferenceFragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
/** Defining PreferenceChangeListener */
OnPreferenceChangeListener onPreferenceChangeListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
OnPreferenceChangeListener listener = (OnPreferenceChangeListener) getActivity();
listener.onPreferenceChange(preference, newValue);
return true;
}
};
}
}
性別TextView在哪裏?另一部分活動還是什麼? –