java - Android, 在一个layout中include多个相同的组件,如何为每个组件中的子view设置不同的属性?
PHP中文网
PHP中文网 2017-04-18 09:06:48
0
5
374

比如我创建了一个layout,里面有一个button,然后在另外一个界面中include了这个layout四次,接着我想为四个button设置不同的text,应该如何完成?

PS0: 单个button只是举个例子,实际上是一个比较复杂的layout
PS1: 实际应用中如果需要在一个layout中多次使用相同的非官方组件,该如何解决这个问题?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(5)
迷茫

Set the id for each include, you can find different Views based on different ids and get the controls in them based on the View.

迷茫

Directly use findViewById(buttonName) to get the corresponding Button, and then set the corresponding requirements

黄舟

You cannot just use Java to set it in xml

PHPzhong

My friend said earlier that setID is OK, and so is setTAG

迷茫

xml里可以使用DataBindingTechnical implementation.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!