2012-05-18 10 views
14

मैं इस कोड को एडिटटेक्स्ट पर एक नियंत्रण डालूंगा ताकि यह केवल हेक्साडेसिमल संख्या स्वीकार कर सके। मैं यह करने के बारे में कैसे जा सकता हूं?मैं केवल हेक्साडेसिमल संख्याओं के इनपुट में एडिटटेक्स्ट कैसे सेट करूं?

bin = (EditText)findViewById(R.id.editText02); 
hex = (EditText)findViewById(R.id.editText3); 
dec = (EditText)findViewById(R.id.editText1); 
oct = (EditText)findViewById(R.id.editText04); 
+0

उपयोगकर्ता setInputType() edittext के लिए संपत्ति .. –

उत्तर

3

टेक्स्टवॉचर भी अच्छा विकल्प है, हालांकि मैं कस्टम फ़िल्टर का उपयोग करना पसंद करता हूं। जिससे सरल तरीके से, InputFilter का उपयोग करें और मक्खी पर हर चार का नियंत्रण लेने, नीचे दिए गए उदाहरण देख रहा है उम्मीद है कि इस मदद करता है

import android.text.InputFilter; 
    import android.text.InputType; 

    EditText input_moodMsg; 
    // initialize this edittext etc etc 
    //.... 
    // here comes the filter to control input on that component 
    InputFilter inputFilter_moodMsg = new InputFilter() { 
       @Override 
       public CharSequence filter(CharSequence source, int start, int end,Spanned dest, int dstart, int dend) { 

        if (source.length()>44) return "";// max 44chars 

// Here you can add more controls, e.g. allow only hex chars etc 

        for (int i = start; i < end; i++) { 
         if (!Character.isLetterOrDigit(source.charAt(i)) && !Character.isSpaceChar(source.charAt(i)) 
           && source.charAt(i)!='-' 
           && source.charAt(i)!='.' 
           && source.charAt(i)!='!' 
           ) { 
          return "";  
         }  
        } 
        return null; 
       } 
      }; 
      input_moodMsg.setFilters(new InputFilter[] { inputFilter_moodMsg }); 
      input_moodMsg.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); 
0

क्या उपयोगकर्ता में टाइप कर सकते हैं के नियंत्रण के लिए, अपना EditTexts को TextWatcher जोड़ें।

36

अपने Android लेआउट एक्सएमएल फ़ाइल में EditText के लिए निम्न विशेषताओं को जोड़ने:

<EditText 
android:digits="ABCDEF" 
android:inputType="textCapCharacters" 
/> 

पहली विशेषता केवल इन अंकों के साथ इनपुट की अनुमति देता है। कोई अन्य इनपुट अस्वीकार कर दिया गया है और प्रदर्शित नहीं किया गया है। दूसरी विशेषता वर्णों को कैपिटल करती है। http://mobile.antonio081014.com/2012/04/how-to-let-input-of-edittext-only-be.html

+0

जोड़ा जा रहा है एंड्रॉयड:

क्रेडिट इस ब्लॉग पोस्ट को जाता है maxLength = "2", अगर मैं "TT11" लिखते हैं, तो EditText खाली रहता है, के बजाय "11" रखना – jsanmarb

संबंधित मुद्दे

 संबंधित मुद्दे