我在首以這種方式創建按鈕:如何PreferenceActivity
<PreferenceScreen>
<Preference
android:key="resetBD"
android:title="@string/ajustes_almacenamiento"
android:summary="@string/ajustes_almacenamiento_desc"
android:widgetLayout="@layout/pref_reset_bd_button" >
</Preference>
</PreferenceScreen>
佈局/ pref_reset_bd_button.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/submit_layout_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:weightSum="10">
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/resetButton"
android:text="Reset"
android:layout_width="wrap_content"
android:onClick="submitWifiToDevice"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
在PreferenceFragment我successfuly訪問/獲取按鈕這樣做:
View footerView = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.pref_reset_bd_button, null, false);
resetButton= (Button) footerView.findViewById(R.id.resetButton);
但是當我嘗試更改按鈕文字
resetButton.setText("NEW ONE");
(或禁用)什麼也沒有發生。我究竟做錯了什麼?
您必須在屏幕可見之前刷新屏幕。抱歉從頭我不知道目前如何。 – greenapps
你是否把setText放在任何條件下? – garima
我看到在android-studio debuger該按鈕獲取新文本,但它不在模擬器中更新 –