मैं अपने एंड्रॉइड ऐप में लेआउट को बाध्य करने के लिए डेटा बाइंडिंग का उपयोग कर रहा हूं।मेरे बाध्यकारी के लिए inflate विधि नहीं मिला है (एंड्रॉइड, डेटा बाइंडिंग का उपयोग करना।)
मैंने अपना लेआउट (my_custom.xml) सेट किया है और बाध्यकारी वर्ग जेनरेट किया गया है (MyCustomBinding), लेकिन एंड्रॉइड स्टूडियो को बाध्यकारी वर्ग की .inflate (...) विधि को तुरंत नहीं लगता है, अंकन यह एक त्रुटि के रूप में (लाल पाठ!)।
हालांकि यह कोड सही लगता है, क्योंकि यह संकलित करता है और एक एपीके में ठीक बनाता है।
मैं एंड्रॉइड स्टूडियो को सही तरीके से अपडेट करने के लिए कैसे प्राप्त करूं?
कोड उदाहरण:
public class MyCustomView extends FrameLayout {
public MyCustomView(Context context) {
this(context, null, 0);
}
public MyCustomView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
MyCustomBinding binding = MyCustomBinding.inflate(inflater, this, true);
binding.aButton.setText("Whatever");
}
}
लेआउट के रूप में परिभाषित किया गया है:
यह मेरा कस्टम देखें कोड है (लाल रंग से हाइलाइट)
: यहाँ
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/a_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me!"
android:padding="10dp"
android:background="#000"
android:textColor="#fff"
android:layout_gravity="center"
/>
</FrameLayout>
</layout>
कृपया अपना कोड पोस्ट करें। क्या आप गतिविधि या टुकड़े का उपयोग कर रहे हैं? –
"MyCutom बाइंडिंग" कक्षा कोड पोस्ट करें। –
यह मुझे एंड्रॉइड स्टूडियो 2.2 में एक बग होने के लिए प्रतीत होता है। मैं महीनों तक इस मुद्दे के बिना डेटा बाइंडिंग का उपयोग कर रहा हूं जब तक कि मैंने आज अपग्रेड नहीं किया, और अब मैं इसे भी देख रहा हूं। यदि आप इसका अनुसरण करना चाहते हैं तो एक [बग रिपोर्ट] (https://code.google.com/p/android/issues/detail?id=222194) है। –