简体   繁体   中英

Android: Can a view (not a viewgroup) contain another view?

I mean something like this

public class ConditionalEditText extends EditText implements TextWatcher
{
    TextView tv;
    ....
}

The TextView is supposed to be displayed only when the EditText satisfies some user specified condition.

I tried to do it like this

public class ConditionalEditText extends LinearLayout implements TextWatcher
{
    EditText edt;
    TextView tv;
    ....
}

but then I cannot specify different XML attributes for edt for different instances of the view in my main layout.

不,只有ViewGroup可以有子视图

Turns out there is a way to do this after all. You can anchor a PopupWindow containing any view(s) you want to another View, which is just what I wanted. I got the code to do so from this link and modified it for my needs.

http://code.google.com/p/simple-quickactions/

All thanks to Qberticus for making it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM