因此,我的首选项中有 EditText,我想获取文本并将其用作字符串。然后我想每次单击按钮时都使用该字符串,它将我的另一个 EditText 文本设置为首选项中的字符串。代码:
<EditTextPreference android:title="Uredi Text"
android:key="ime"
android:summary="ime pjesme"
/>
Java代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String b1t = preferences.getString("ime", "DEFAULT");
et1 = (EditText) findViewById(R.id.editText1);
//Button Click
public void button(View view) {
et1.setText(b1t);
}