में edittext के लिए इनपुट समय तक सीमित कैसे करें मुझे उपयोगकर्ता को केवल ##: ## फ्लाई पर संपादन टेक्स्ट में प्रारूप करने की अनुमति देना है, क्या इसे प्राप्त करने का कोई तरीका है? मैंने कोड के नीचे उपयोग किया है लेकिन यह काम नहीं कर रहा है।एंड्रॉइड
मैं 45623: 5689 जैसे 24 से अधिक मान दर्ज करने में सक्षम हूं।
edit.setInputType(InputType.TYPE_DATETIME_VARIATION_TIME)
भी android:text="time"
भी काम नहीं कर रहा है।
मैं इस चीज़ को कैसे प्राप्त कर सकता हूं। क्या कोई मुझे सुझाव दे सकता है कि मैं यह कैसे कर सकता हूं।
मैं उपयोगकर्ता को 23 मूल्य तक पहले 2 स्थानों में प्रवेश करने की अनुमति देना चाहता हूं और फिर compulasary: और फिर उपयोगकर्ता 59 मान तक की अनुमति दे सकता है।
उदाहरण
23:59 correct
24:05 incorrect
02:56 correct
02:79 incorrect
के लिए मैं इस अनुकूलित फिल्टर का भी इस्तेमाल किया है, लेकिन इसके काम नहीं कर रहा
मैं कुछ और कहाँ अतः में से इस कोड को मिला है।
कोड:
InputFilter timeFilter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
int dstart, int dend) {
if (source.length() == 0) {
return null;// deleting, keep original editing
}
String result = "";
result += dest.toString().substring(0, dstart);
result += source.toString().substring(start, end);
result += dest.toString().substring(dend, dest.length());
if (result.length() > 5) {
return "";// do not allow this edit
}
boolean allowEdit = true;
char c;
if (result.length() > 0) {
c = result.charAt(0);
allowEdit &= (c >= '0' && c <= '2');
}
if (result.length() > 1) {
c = result.charAt(1);
allowEdit &= (c >= '0' && c <= '9');
}
if (result.length() > 2) {
c = result.charAt(2);
allowEdit &= (c == ':');
}
if (result.length() > 3) {
c = result.charAt(3);
allowEdit &= (c >= '0' && c <= '5');
}
if (result.length() > 4) {
c = result.charAt(4);
allowEdit &= (c >= '0' && c <= '9');
}
return allowEdit ? null : "";
}
};
संपादित प्रश्न: main.xml फ़ाइल कोड
<?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="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/txtRecipientName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="@string/recipient_name" />
<EditText
android:id="@+id/edTxtRecipient"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:paddingLeft="20dp" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/txtParcelDeliverTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="@string/delivered_time" />
<EditText
android:id="@+id/edTxtParcelDeliverTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:paddingLeft="20dp" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/btnRecipient_OK"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@android:string/ok" />
</LinearLayout>
</LinearLayout>
इस कोड काम कर रहा है, लेकिन अगर मैं पहले वर्णमाला डालने और फिर उचित मान सम्मिलित अपने काम नहीं कर रहा क्योंकि source
में इसका पिछला वर्ण मूल्य है।
मैं अभी-अभी अपने कोड की कोशिश की, मैं XML फ़ाइल में समस्या लगता है मैंने कल उल्लेख किया था, अपनी गतिविधि के संपादन टेक्स्ट के एक्सएमएल से किसी इनपुट प्रकार सत्यापन को हटाएं और फिर यह ठीक काम करता है –
मदद के लिए धन्यवाद प्रतीक्षा करें, मैं अपना एक्सएमएल फ़ाइल कोड डालूंगा। कोई सत्यापन या कोई इनपुट टाइप सत्यापन नहीं है। –
मेरा अद्यतन प्रश्न देखें –