[英]Text not changing when password and confirm password are the same KOTLIN android studio
[英]Android - Password transformation (convert the * to a text )
這是一個將密碼從點轉換為*或星號的android類,但是我想向用戶顯示一些預定義的文本而不是星號,為此我用char數組yay中的字符替換了星號。但是當我使用一鍵點擊。P在記錄器中無限次打印。有人可以解釋嗎?
class AsteriskPasswordTransformationMethod extends PasswordTransformationMethod {
static int a=0;
char[] yay= {'P','l','e','a','s','e','w','r','i','t','e'};
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
private class PasswordCharSequence implements CharSequence {
private CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source; // Store char sequence
}
public char charAt(int index) {
Log.v("what is the char",""+yay[a]);
char x= yay[a]; // This is the important part
return x;
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); // Return default
}
}
我想這就是你想要的:
Log.v("what is the char",""+yay[index]);
char x= yay[index];
它僅打印“ p”,因為a
始終為0,因此yay[a]
始終為“ p”。
但是,為什么要這樣做呢? 只需將字段的輸入類型設置為TYPE_TEXT_VARIATION_PASSWORD
然后android會為您完成。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.