RobotoAttributeSet
gibi oluşturulan ve özel görünüme geçirilen iletiler hiçbir zaman okunmuyor veya yanlış şekilde oluşturulmuyor. İşte Robolectric'in RoboAttributeSet'i hiçbir zaman okunmadı
ArrayList<Attribute> attributes = new ArrayList<>();
attributes.add(
new Attribute("com.package.name:attr/CustomButton_inputType",
String.valueOf(2), "com.package.name")); // no matter what value I use (2)
AttributeSet attrs =
new RoboAttributeSet(attributes, Robolectric.application.getResources(), CustomButton.class);
CustomButton button = new CustomButton(Robolectric.application, attrs);
olan benim
attr.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomButton">
<attr name="inputType" format="enum">
<enum name="text" value="0"/>
<enum name="textEmailAddress" value="1"/>
<enum name="password" value="2"/>
</attr>
</declare-styleable>
</resources>
CustomButton bir kısmı:
private void applyAttributes(Context context, AttributeSet attrs) {
TypedArray typedArray = context.getTheme()
.obtainStyledAttributes(attrs, R.styleable.CustomButton, 0, 0);
try {
int typeValue = // is always 0
typedArray.getInt(R.styleable.CustomButton_inputType, 0);
switch (typeValue) {
case 0:
// do something
break;
case 1:
// do something
break;
case 2:
// do something
break;
default:
// just do nothing
break;
}
} finally {
typedArray.recycle();
}
}
Yani olursa olsun özelliklerini hazırlarken ben ayarladıklarınızla değeri (örnekte 2
), her zamanolsun typeValue
için.
Yanlış bir şey yapıyorum? Çok teşekkürler!
benim kurulum benzer denedim deneyin ve ayrıca styledArray boş olduğunu teyit etmektedir. Ancak, Görünümü etkinlik ve xml kaynağından şişirmeye çalıştığımda boş olmadığını görüyorum. Bu şekilde test yapmayı düşünür müsün? –
Bir bilet oluşturdum https://github.com/robolectric/robolectric/issues/1478 –