स्थापित करने के लिए मैं एक CompositeComponent (EditText + ImageButton) जब edittext सामग्री बटन पर क्लिक साफ कर दिया जाएगा है Styleable घोषणा करते हैं। यह ठीक काम कर रहा है। मेरी समस्या मेरे घटक को विशेषताओं को सेट कर रही है। मैं अपने घटक में विशेषताओं को सेट करने के लिए घोषणा-शैली योग्य उपयोग कर रहा हूं।उपयोग कस्टम घटक इनपुट प्रकार
मैं स्थापित करने minLines, Maxlines और textcolor में सफल रहा हूँ।
मैं कैसे एक्सएमएल के माध्यम से मेरी घटक को inputtype सेट कर सकते हैं।
मेरी attributes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CET">
<attr name="MaxLines" format="integer"/>
<attr name="MinLines" format="integer"/>
<attr name="TextColor" format="color"/>
<attr name="InputType" format="integer" />
<attr name="Hint" format="string" />
</declare-styleable>
</resources>
और mycomponent के उपयोग main_layout.xml में:
<com.test.ui.ClearableEditText
xmlns:cet="http://schemas.android.com/apk/res/com.test.ui"
android:id="@+id/clearableEditText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
cet:MaxLines="2"
cet:MinLines="1"
cet:TextColor="#0000FF"
cet:InputType="" <---I cant set this property--------->
cet:Hint="Clearable EditText Hint">
</com.test.ui.ClearableEditText>
साधारण Edittext उपयोग:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned" <--------I want to use this property--------> >
मैं अपने विशेषता में Enum का उपयोग नहीं कर सकते। एक्सएमएल। android:inputType="numberSigned"
को मेरे cet:InputType
में कैसे देखें?
संपादित करें:
इस तरह मैं अपने ClearableEditText.java
TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CET,0, 0);
int minLines = a.getInt(R.styleable.CET_MinLines, 1);
int maxLines = a.getInt(R.styleable.CET_MaxLines, 100);
String hint = a.getString(R.styleable.CET_Hint);
int textColor = a.getColor(R.styleable.CET_TextColor, Color.BLACK);
int inputType = a.getInt(R.styleable.CET_InputType, -108);
Log.i(TAG, "ClearableEditText: Min Line "+minLines +" Max Lines: "+maxLines+" Hint "+hint+" Color: "+textColor+" Input Type: "+inputType);
edit_text.setMaxLines(maxLines);
edit_text.setMinLines(minLines);
edit_text.setTextColor(textColor);
edit_text.setHint(hint);
if(inputType != -108)
edit_text.setInputType(inputType);
आप देख सकते हैं वहाँ editText को inputType संपत्ति बताए साथ कोई समस्या नहीं है में गुण आवंटित।
आप क्या त्रुटि क्यों मिलती है का उपयोग करें? – Mayank
मुझे कोई त्रुटि नहीं मिली।यह ठीक काम कर रहा है। मुझे नहीं पता कि इनपुट प्रकार कैसे असाइन करें ?? कच्चे पूर्णांक मूल्य देने के बजाय मैं एंड्रॉइड में enum (android: inputtype) का उपयोग करना चाहता हूं। –