Android的 - 的用户名可用的Ajax风格的自动检查用户名、风格、Android、Ajax

2023-09-10 14:04:05 作者:梦想才让心跳存在、

我建立一个Android应用程序中,用户需要选择一个昵称。现在,两个用户不可能有相同的昵称。我看到的.NET形式,我们可以在用户类型或presses标签使用Ajax调用验证一个特定的用户名的可用性。

I am building an Android app in which user are required to choose a nick name. Now, two users cannot have same nick name. I have seen forms on .net where we can verify the availability of a particular username while user types or presses tab using Ajax calls.

我的问题是 - 什么事情一样,可用于Android。我可以查询我的服务器在运行,并验证一个昵称的可用性。

My questions is - is anything like that available for Android. Can I query my server on the fly and verify the availability of a nick name.

非常感谢您的答复。如果有任何教程,样本或Android文档引用我需要看一下,请指引我到这一点。

Thanks a lot for your responses. If there are any tutorials, samples or Android doc references I need to look at please guide me to that.

推荐答案

您的可以的每个键preSS事件指定输入组件询问用户当前输入的用户名的服务器的数据库(的EditText 等),但可能是pretty的大量网络资源,催生了大量的线程来处理:

you could query your server's database of users with the currently entered username on every keypress event for the specified input component(EditText, etc), but that might be pretty network intensive and spawn a lot of threads to handle:

添加 TextWatcher 您输入的EditText 或任何用户输入他的名字 在 onTextChanged 方法,你会产生一个线程来联系你的数据库沿的CharSequence 值发送。从你的服务器的响应将输出一些JSON或许还有一个布尔值属性,它说,如果用户名是否可用 在用户点击确定,预计注册为自理他们的名字。最后的检查需要作出之前,他们实际上得到这个绰号,因为可用性可能会因为(比如说一吨的人正在注册一次全部)​​改变 add a TextWatcher to your input EditText or whatever the user is entering his name into in the onTextChanged method, you would spawn a thread to contact your database sending along the CharSequence value. the response from your server would output some JSON perhaps with a boolean property which says if the username is available or not user hits "ok" and expects their name to be registered for themself. a final check needs to be made before they actually get this nickname, as the availability may have changed since(say a ton of people are registering all at once)

让用户输入自己想要的名字 让他们点击保存或注册 在这一点上,沿着上登记数据,并将其保存在数据库中,如果他们的名字是否可用。否则,让用户知道它是不是他们必须再试

在应用程序启动(权之前,他们必须选择一个名字),请联系您的服务器的数据库,并发送应用程序的响应拿着已经采取的名称列表。

when you app starts(right before they must pick a name), contact your server's database and send the app a response holding a list of names that are already taken.

这种方式,你可以很容易地检查名称取自本地在手机上而不是发送了一个请求,检查。

this way, you can easily check if the name is taken locally on the phone rather then sending off a request to check.

您仍必须始终将其保存在服务器端

you must still always check the availability of the nickname right before saving it on the server side

编辑: 我实现了#2,这似乎是这就是大多数应用程序做注册一个唯一的名称(即我见过)

edit: I've implemented #2, which seems like that's what the majority of apps do for registering a unique name(that ive seen)

问题#1   - 在1信用户输入(网线开始)   - 用户enteres另一封信(另一个线程启动)   - 用户输入第三个字母(另一个线程)   - 线程2结束第一,名称是有效的,通知用户   - 线程1结束,名无效,通知用户   - 线程3完成后,名无效,用户被告知

problem with #1 - user enters in 1 letter(network thread started) - user enteres another letter(another thread started) - user enters a 3rd letter(another thread) - thread 2 finishes first, name is valid, user is notified - thread 1 finishes, name is invalid, user is notified - thread 3 finishes, name is invalid, user is notified

主题2把4秒 线程1把5秒 线3把5秒

thread 2 took 4 seconds thread 1 took 5 seconds thread 3 took 5 seconds

说用户保持对输入25个字母,有很多你要跟踪的条款,如果该名称是有效还是无效,如果什么线仍在运行,等等

say user keeps typing for 25 letters, there is a lot you have to keep track of in terms if the name is valid or not, if and what threads are still running, etc

这种做法似乎有点太繁琐了这样一个简单的注册任务,太麻烦

this approach seems a bit too tedious for such a simple registration task, too much hassle

问题#3   - 需要1个额外的网络请求到服务器

problem with #3 - requires 1 extra network request to the server

我喜欢这种方法,因为你可以轻松快速地通知用户,如果他们的名字都无需任何线程(取决于你有多大的用户列表),或者担心它会花费多长时间检查

i like this approach because you can easily and quickly notify the user if their name is available without any threading(depending how large your user list is) or worrying about how long it will take to check

2号是简单,方便,并能有机会只需要一台服务器的请求

number 2 is simple, easy, and can have the chance to only require 1 server request

 
精彩推荐
图片推荐