久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

按“."多次(鍵入時(shí)在 EditText 中驗(yàn)證 IP 地址

press quot;.quot; many times (validate ip address in EditText while typing)(按“.多次(鍵入時(shí)在 EditText 中驗(yàn)證 IP 地址))
本文介紹了按“."多次(鍵入時(shí)在 EditText 中驗(yàn)證 IP 地址)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我有以下 EditText:

I have the following EditText:

 <EditText
android:id="@+id/ip"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="numberDecimal">
</EditText>

我想用它來(lái)獲取IP地址.但它不允許我輸入."(句號(hào))不止一次,因?yàn)?inputtype 設(shè)置為 numberDecimal.關(guān)于如何獲得多個(gè)."的任何建議同時(shí)將 inputType 設(shè)置為數(shù)字.

I want to use this to get ip address. But it will not allow me to type '.' (period sign) more than once because the inputtype is set to numberDecimal. Any suggestion on how to get more than one '.' while setting inputType to numbers.

推薦答案

你需要?jiǎng)?chuàng)建自己的InputFilter:http://developer.android.com/reference/android/text/InputFilter.html

看看我前段時(shí)間寫(xiě)的這個(gè)答案:如何設(shè)置 Edittext 視圖只允許兩個(gè)數(shù)值和兩個(gè)十進(jìn)制值,如 ##.##

Take a look at this answer I wrote some time ago: How to set Edittext view allow only two numeric values and two decimal values like ##.##

這是對(duì)該過(guò)濾器的修改以驗(yàn)證 ips.它檢查是否存在四位數(shù)字,用點(diǎn)分隔,并且沒(méi)有一個(gè)大于 255.驗(yàn)證是實(shí)時(shí)進(jìn)行的,即在打字時(shí).

Here is an adaptation to that filter to validate ips. It checks for the presence of four digits, separated by dots and none of them bigger than 255. The validation occurs in real time, i.e., while typing.

    EditText text = new EditText(this);
    InputFilter[] filters = new InputFilter[1];
    filters[0] = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if (end > start) {
                String destTxt = dest.toString();
                String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end) + destTxt.substring(dend);
                if (!resultingTxt.matches ("^\d{1,3}(\.(\d{1,3}(\.(\d{1,3}(\.(\d{1,3})?)?)?)?)?)?")) { 
                    return "";
                } else {
                    String[] splits = resultingTxt.split("\.");
                    for (int i=0; i<splits.length; i++) {
                        if (Integer.valueOf(splits[i]) > 255) {
                            return "";
                        }
                    }
                }
            }
        return null;
        }
    };
    text.setFilters(filters);

這篇關(guān)于按“."多次(鍵入時(shí)在 EditText 中驗(yàn)證 IP 地址)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開(kāi)的 EditText 中的開(kāi)始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問(wèn)題)
主站蜘蛛池模板: 亚洲色图第一页 | 国产目拍亚洲精品99久久精品 | 欧美一区永久视频免费观看 | 天天看片天天干 | 欧美综合一区二区 | 国产精品片 | 综合一区| 亚洲天堂中文字幕 | 日韩在线免费视频 | 欧美激情视频一区二区三区在线播放 | 国产日产欧产精品精品推荐蛮挑 | 中文字幕一区二区三区在线观看 | www狠狠爱com| 国产精品自产拍在线观看蜜 | 日本在线免费视频 | 狼色网 | 欧美aⅴ | 久久久久久久国产 | 欧美视频日韩 | 久久伊人精品 | 国产免费一级一级 | 欧美激情一区二区三区 | 黄色一级大片在线免费看产 | 久久国产精品久久久久久久久久 | 免费黄色大片 | 九九亚洲 | 欧美中文字幕一区二区三区 | 亚洲成人久久久 | 精区3d动漫一品二品精区 | 国产成人99av超碰超爽 | 国产欧美一区二区三区国产幕精品 | 欧美一级三级在线观看 | 香蕉久久a毛片 | 久久久久久久久久影视 | 91视频在线| 蜜臀网| 国产精品视频一二三区 | 青青久在线视频 | 9久久精品 | 日韩一二区在线 | 午夜在线|