android - PreferenceEditText 到字符串

标签 android android-edittext android-preferences

所以我的首选项中有 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);
}

最佳答案

根据开发者文档,您可以只使用 edittextpreference.getText().toString()

关于android - PreferenceEditText 到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13424020/

相关文章:

android - 如何在 android 上使用 ffmpeg 创建播放器?

java - 添加到 eclipse 项目的外部 jar

java - 从动态创建的 editText 获取值输入

android - 按回隐藏软键盘

android - PreferenceFragmentCompat 不监听第一次触摸事件

java - 在谷歌地图的 map 版本2中获取 map 中心

android - 光标移动到输入文本的左侧,而不是在 Honeycomb 上移动到右侧

android - 基于主开关的灰显设置?

android - 工具栏箭头在 NavigationDrawer 的 PreferenceFragment 中不起作用

android - 在网络应用程序上添加广告