私の質問:EditTextを拡張するクラスを作成せずに、これらのカスタム属性の値を読み取ることはできますか?
はい、クラスを拡張せずにこれらの属性を取得できます。このために、がレイアウトファイルを解析するために使用する特別なセットをFactory使用できます。このようなもの:LayoutInflaterActivity
super.onCreate(savedInstanceState);
getLayoutInflater().setFactory(new CustomAttrFactory());
setContentView(R.layout.the_layout);
ここで、CustomAttrFactoryは次のようになります。
public static class CustomAttrFactory implements Factory {
@Override
public View onCreateView(String name, Context context,
AttributeSet attrs) {
String attributeValue = attrs
.getAttributeValue(
"http://schemas.android.com/apk/res/com.luksprog.droidproj1",
"attrnew");
Log.e("ZXX", "" + attributeValue);
// if attributeValue is non null then you know the attribute is
// present on this view(you can use the name to identify the view,
// or its id attribute)
return null;
}
}
アイデアはブログ投稿から来ています、あなたは追加情報のためにそれを読むことを望むかもしれません。
また、そのカスタム属性(または他の属性がある場合は属性)に応じてandroid:tag="whatever"、追加のデータを渡すために使用できます(後でActivitywithで取得しますview.getTag())。
これらのカスタム属性を使用せず、現在のアプローチを再考することをお勧めします。