android - Why cannot I inflate and add a ViewGroup as a child view in constructor of another ViewGroup? -


मेरे पास RelativeLayout नामित LabelMenuButton से एक वर्ग विस्तारित है। इसके कंस्ट्रक्टर के अंदर, मैं कर रहा हूं:

  सार्वजनिक लेबलमेनबु बटन (संदर्भ संदर्भ, एट्रिबेटसेट एटर्स) {सुपर (संदर्भ, एटर्स); TypedArray a = context.getTheme ()। प्राप्त स्टाइल गुण (attrs, R.styleable.LabelMenuButton, 0, 0); स्ट्रिंग हेडिंग टेक्स्ट; अक्षर मूल्य पाठ; {HeadingText = a.getString (R.styleable.LabelMenuButton_headingText) का प्रयास करें; ValueText = a.getString (R.styleable.LabelMenuButton_valueText); } अंत में {a.recycle (); } एडव्यू (फुटेज (getContext (), आर। लय आउट.दृश्य_लैब_मेनू_बटन, यह)); TVHeading = (TextView) findViewById (R.id.tv_lbl_menu_btn_heading); TvValue = (TextView) ढूंढें ViewById (R.id.tv_lbl_menu_btn_value); setHeadingText (headingText); setValueText (valueText); }  

मैं एक गतिविधि के XML लेआउट में LabelMenuButton वर्ग का उपयोग कर रहा हूं:

  & lt; com.blah.blah blah.LabelMenuButton एंड्रॉयड: layout_width = "wrap_content" एंड्रॉयड: layout_height = "wrap_content" एंड्रॉयड: layout_alignParentBottom = "true" एंड्रॉयड: layout_alignParentRight = "true" एंड्रॉयड: layout_marginBottom = "150dp" ऐप्स: headingText = "नमूना शीर्षक" एप्लिकेशन: valueText = "नमूना मान" / & gt;  

लेकिन मुझे यह अपवाद मिलता है जब, मुझे विश्वास है, कि गतिविधि की सामग्री सेट की जा रही है:

  गतिविधि ComponentInfo शुरू करने में असमर्थ {com.blah.blah। blah / com.blah.blah.blah.MyActivity}: android.view.InflateException: बाइनरी एक्सएमएल फ़ाइल लाइन # 105: त्रुटि वर्ग बढ़ा-चढ़ाकर com.blah.blah.blah.LabelMenuButton  

view_label_menu_button .xml:

  & lt;? Xml संस्करण = "1.0" एन्कोडिंग = "यूटीएफ -8"? & Gt; & LT; LinearLayout xmlns: एंड्रॉयड = "http://schemas.android.com/apk/res/android" एंड्रॉयड: अभिविन्यास = "ऊर्ध्वाधर" एंड्रॉयड: layout_width = "match_parent" एंड्रॉयड: layout_height = "match_parent" & gt; & LT; TextView एंड्रॉयड: आईडी = "@ + id / tv_lbl_menu_btn_heading" एंड्रॉयड: layout_width = "wrap_content" एंड्रॉयड: layout_height = "wrap_content" एंड्रॉयड: पाठ = "शीर्षक" / & gt; & LT; TextView एंड्रॉयड: आईडी = "@ + id / tv_lbl_menu_btn_value" एंड्रॉयड: layout_width = "wrap_content" एंड्रॉयड: layout_height = "wrap_content" एंड्रॉयड: पाठ = "मान" / & gt; & Lt; / LinearLayout & gt;  

  addView (बढ़ (getContext (), R.layout .view_label_menu_button, यह));  

फुलाओ () पहले से ही आपूर्ति किए गए मूल रूट ( यह यहां तक) तक फुलाए गए दृश्य को जोड़ता है जब तक कि आप इसका उपयोग नहीं करते attachToRoot से झूठे पर सेट करें। माता-पिता को फिर से दृश्य जोड़ने के कारण "पहले से ही एक माता पिता" अपवाद होता है।

आप addView () यहां निकाल सकते हैं।


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -