的EditText用户输入 [英] EditText User Input

查看:133
本文介绍了的EditText用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好Android开发者。我做我的研究,我不能似乎知道如何做到以下几点:1,我希望用户在一个EditText输入一些输入(数字)和我想要的任何号码,他写上的EditText呆在那里,直到他的水龙头的EditText,并决定输入另一个号码。我的意思是住在这里,是他离开的应用程序,当他回来的,对于输入到那里。请指导我,因为我是个初学者一步一步吧。

Hello Android Developers. I did my research and i cant seem to know how to do the following: 1.-I want the user to enter some input (Numbers) in an EditText and i want whatever number he wrote on that edittext to stay there until he taps that edittext, and decides to input another number. What i mean by "staying there" is that when he leaves the app and he comes back in, for the input to be there. Please guide me step by step since im a begginer please.

请注意:我想为它不会有保存按钮,只为输入留在原地

Note:I would like for it to not have a "save" button, just for the input to stay put.

推荐答案

首先,在你的XML的EditText上,确保使用的android:inputType下=号,所以它是用户输入的数字更容易

First, in your xml for the EditText, make sure to use android:inputType="number" so it is easier for the user to enter numbers.

二,在你的片段或活动的onPause()(取持有的EditText,我将承担例如code的活动),保存您的EditText值:

Second, in onPause() of your Fragment or Activity (whichever holds the EditText, I will assume an Activity for the example code), save your EditText value :

String numbers = mET.getText().toString();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putString("numbers", numbers).apply();

然后,在onResume(),把它放回去:

Then, in onResume(), put it back:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String numbers = prefs.getString("numbers");
mET.setText(numbers);

我希望帮助!

这篇关于的EditText用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆