Bir TextView ve EditText öğelerini, her bir öğe için varsayılan değerlerden geçmek üzere özel xml öğeleri kullanan bir bileşik denetimde birleştirmeye çalışıyorum. Burada öğreticiler/docs bakarak oldum:
Building Compound Controls
Passing Custom AttributesÖzel XML Öznitelikleriyle Bileşik Denetimleri Oluşturma
var bugüne kadar ne.
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>
Benim Ana Düzen:
<?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>
Benim Bileşik Kontrolü, FREETEXT: Ben programı çalıştırdığınızda
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();
}
}
Ben görünümler Tamam görüyorum ama CharSequence değerinin değeri her zaman boş. Birisi bana nerede yanlış gittiğimi söyleyebilir mi?
Ve doğru yardım talebinde sonra sorunu fark gerçeğini seviyorum:
sorun benim özel XML elemanları benim ad şöyle olmalıydı oldu! Başka bir yerde aynı cevap için çok fazla kazım yaptın. Teşekkürler! – gregko