समझ में नहीं आ रहा है ... केवल कुछ दृश्य की संपत्ति कैसे सेट करें यदि परिवर्तनीय फ़ील्ड शून्य नहीं है?
उदाहरणडेटा बाध्यकारी: अगर संपत्ति शून्य नहीं है
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="item"
type="com.test.app.Item" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="16dp"
android:src="@{item.getDrawable()}"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:layout_marginStart="72dp"
android:layout_toLeftOf="@id/action"
android:layout_toStartOf="@id/action"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@color/black_87"
android:textSize="16sp"
android:text="@{item.getTitle()}"/>
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web|email"
android:linksClickable="false"
android:singleLine="true"
android:textColor="@color/black_54"
android:textSize="14sp"
android:text="@{item.getSubtitle()}"/>
</LinearLayout>
</RelativeLayout>
</layout>
के लिए आइटम में से कुछ फ़ील्ड रिक्त हो सकता है और मैं अनावश्यक रूप से लेआउट विचारों के तरीकों कॉल नहीं होंगे। और मुझे NullPointerException
नहीं मिलेगा। मैं केवल संपत्ति कैसे सेट कर सकता हूं यदि यह शून्य नहीं है?
पीएस अंग्रेजी के लिए खेद है।
मुझे पता है। जैसा कि मैंने समझा है कि मूल्य शून्य है, तो दृश्य में कॉल को कॉल करना असंभव है? –
मुझे खेद है कि मुझे यकीन नहीं है कि आप यहां क्या पूछ रहे हैं। क्या आप पिछले मान को रखने की कोशिश कर रहे हैं यदि नया मान शून्य था? यह सुनिश्चित नहीं है कि डेटा बाध्यकारी के माध्यम से इसे पूरा करने का यह एक अच्छा तरीका है। नए दो-तरफा डेटा बाध्यकारी का उपयोग किया जा सकता है, मुझे लगता है कि जब भी यह शून्य नहीं होता है तो कुछ (संभवतः अन्य) ऑब्जेक्ट का मान सेट करके अनुमान लगाया जा सकता है। लेकिन मुझे संदेह है कि यह इसके बारे में जाने का एक अच्छा तरीका है। –
इसके बजाय उपयोग किए गए चर को विभाजित करने का एक तरीका होगा, इसके बजाय प्रत्येक संपत्ति के लिए एक होना चाहिए। आइटम की बजाय स्ट्रिंग टाइप करें। –