Как сделать текстовое поле EditText доступным для нескольких макетов XML в приложении Android? - PullRequest
0 голосов
/ 06 марта 2012

Я хочу разместить EditText в моем приложении для Android, которое останется неизменным для трех макетов или, более конкретно, поле EditText будет доступно для трех действий, имеющих разные другие свойства (например, разные TextView, Button и т. Д.) Может кто-нибудь сказать мне, как можноЯ сделаю это?Заранее спасибо:)

1 Ответ

0 голосов
/ 10 марта 2012
public class PhoneEditText extends EditText {

    public PhoneEditText(Context context) {
        super(context);
        init();
    }

    public PhoneEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public PhoneEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
            // set your input filter here
    }
}


n XML layout you would simply use the full path to your custom class instead EditText:

<my.package.path.to.PhoneEditText android:id="@+id/one"
   attribute="value (all EditText attributes will work as they did before)" />

<my.package.path.to.PhoneEditText android:id="@+id/two"
   attribute="value (all EditText attributes will work as they did before)" />


that's it....
...