Android 警报对话框数字输入
好的,大家好,我有一个警报对话框,显示一个编辑文本,要求在活动中输入密码。一切正常我也尝试使用一个简单的布局文件。现在的问题是,每当我尝试强制执行数字输入时,它都会显示数字输入,但拒绝显示在日志中输入的任何数字输入,并显示空白字符串。它适用于常规文本。但是还有一个奇怪的问题,如果您输入的第一个字符是数字,那么它仍然存在相同的问题,但如果您输入一些非整数字符然后是数字,那么就可以了,例如。 a5 很好,但如果你输入 5,那么当你专门强制执行 android:inputType="number" 时就会出现问题 现在,当我在常规活动中尝试此操作(作为健全性检查)时,它工作正常,只是不在警报对话框中,
这是相关代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/password_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="Password"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:password="true"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
public void passwordChecker() {
// TODO Auto-generated method stub
//final EditText input = new EditText(PrivacyActivity.this);
//input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
//input.setInputType(InputType.TYPE_CLASS_NUMBER);
//input.setInputType(InputType.TY);
//input.setTransformationMethod(PasswordTransformationMethod.getInstance());
LayoutInflater factory = LayoutInflater.from(mContext);
final View view = factory.inflate(R.layout.password, null);
final EditText mPassword=(EditText) view.findViewById(R.id.password);
//final EditText test=(EditText) findViewById(R.id.password);
final EditText input = new EditText(mContext);
if(true){
new AlertDialog.Builder(PrivacyActivity.this).setMessage("Enter the password")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//perform deletion from database
dialog.cancel();
Log.e("error", "Apple "+ mPassword.getText().toString());
}
}).setView(input)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
....
}
}).create().show();
}
}
Ok guys so I have a alert dialog showing a Edittext asking for password in an activity. everything works fine i also tried using a simple layout file. now the problem is that whenever i try to enforce the numeric input it shows the numeric input but refuses to show any numeric input that is being typed in also in log there blank string show up. It works fine with regular text. But there is also a little weird problem with that if the first charater that u entered is number then it still has the same problem but if u enter some non integer character and then number then it is ok for eg. a5 is good but if u enter 5 then sam problem when u specifically enforce android:inputType="number"
Now when i try this in regular activity(as a sanity check) it works fine just not in the alertDialog
here is the relevance code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/password_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="Password"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:password="true"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
public void passwordChecker() {
// TODO Auto-generated method stub
//final EditText input = new EditText(PrivacyActivity.this);
//input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
//input.setInputType(InputType.TYPE_CLASS_NUMBER);
//input.setInputType(InputType.TY);
//input.setTransformationMethod(PasswordTransformationMethod.getInstance());
LayoutInflater factory = LayoutInflater.from(mContext);
final View view = factory.inflate(R.layout.password, null);
final EditText mPassword=(EditText) view.findViewById(R.id.password);
//final EditText test=(EditText) findViewById(R.id.password);
final EditText input = new EditText(mContext);
if(true){
new AlertDialog.Builder(PrivacyActivity.this).setMessage("Enter the password")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//perform deletion from database
dialog.cancel();
Log.e("error", "Apple "+ mPassword.getText().toString());
}
}).setView(input)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
....
}
}).create().show();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个...
Try this...
所以我发现问题后花了很长时间才做出回应
问题不在于上面的任何一个。由于某种原因,我未能添加上面不存在的代码。
所以我用我的功能之一覆盖了警报对话框
如下。由于我只听
KEYCODE_DPAD_UP
和KEYCODE_DPAD_CENTER
它弄乱了数字键盘输入,
因此对于任何人来说,如果它有助于检查您正在听什么键。
So my bad took me ages to respond after i found the problem
The problem wasn't either of them above. For some reason I failed to add a code that isn't present above.
so i had over-ridded the alert dialog with one of my function
as follows. And since i was only listening to the
KEYCODE_DPAD_UP
andKEYCODE_DPAD_CENTER
it was messing up the numeric keyboard input
so for anyone if it helps check what keys u r listening as well.