简体   繁体   中英

How do I set the behavior for an inflated view?

I have an audio player toolbar activity that has a corresponding layout file.

I need this player to show up at the bottom of another activity. I use a ViewStub and inflate the audio toolbar's layout file in the stub.

How do I access the buttons, etc on this inflated view and how do I set their behavior?

The docs on ViewStub did not mention anything about this (or maybe I totally overlooked something).

I may be doing something fundamentally wrong here so I would appreciate any help I can get :)

Once you've inflated a view, you call findViewById on the view with the ID. eg

View v = ...;
TextView textView = (TextView) v.findViewById(R.id.textview);

if in your xml you had a declaration of a TextView with id "@+id/textview"

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