简体   繁体   English

如何为膨胀视图设置行为?

[英]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. 我使用ViewStub,并在存根中为音频工具栏的布局文件充气。

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). ViewStub上的文档未提及任何内容(或者也许我完全忽略了某些内容)。

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. 扩展视图后,可以在具有ID的视图上调用findViewById。 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" 如果在您的xml中,您声明了ID为“ @ + id / textview”的TextView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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