मैं एक टेक्स्टव्यू और एक संपादन टेक्स्ट को एक यौगिक नियंत्रण में गठबंधन करने का प्रयास कर रहा हूं जो प्रत्येक व्यक्तिगत तत्व के लिए डिफ़ॉल्ट मानों में पास करने के लिए कस्टम xml तत्वों का उपयोग करता है। मैं ट्यूटोरियल/डॉक्स यहाँ पर देख रहा है:
Building Compound Controls
Passing Custom Attributesकस्टम एक्सएमएल विशेषताओं के साथ कंपाउंड नियंत्रण बनाना
क्या मैं अब तक की है।
Attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="FreeText">
<attr name="label" format="string" />
<attr name="default" format="string" />
</declare-styleable>
</resources>
मेरे मुख्य लेआउट:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.example.misc.FreeText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:label="label"
myapp:default="default"
/>
</LinearLayout>
मेरे यौगिक नियंत्रण, FreeText:
public class FreeText extends LinearLayout {
TextView label;
EditText value;
public FreeText(Context context, AttributeSet attrs) {
super(context, attrs);
this.setOrientation(HORIZONTAL);
LayoutParams lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT);
lp.weight = 1;
label = new TextView(context);
addView(label, lp);
value = new EditText(context);
addView(value, lp);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FreeText);
CharSequence s = a.getString(R.styleable.FreeText_label);
if (s != null) {
label.setText(s);
}
a.recycle();
}
}
जब मैं कार्यक्रम चलाने मैं विचारों ठीक देखते हैं लेकिन मेरे CharSequence का मूल्य हमेशा शून्य है। क्या कोई मुझे बता सकता है कि मैं गलत कहां जा रहा हूं?
और मैं सही मदद के लिए पूछ के बाद तथ्य यह है कि आप इस समस्या को देखा प्यार करता हूँ, उससे पहले नहीं:
समस्या यह है कि मेरे कस्टम XML तत्वों के लिए मेरे नाम स्थान इसलिए की तरह किया गया है चाहिए था! आपने मुझे कहीं और जवाब के लिए बहुत खुदाई बचाई है। धन्यवाद! – gregko