我在首以这种方式创建按钮:如何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该按钮获取新文本,但它不在模拟器中更新 –