什么是你的视图的ID命名约定? [英] What's your naming convention for the View IDs?

查看:85
本文介绍了什么是你的视图的ID命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我们很多人而命名的视图的ID被困扰。不像包机制,在一个项目中的资源的ID使用的是一个普通的命名空间。因此,我们必须找出一些方法来命名该领域具有相同的功能,但在不同的布局文件。

I believe that many of us were bothered while naming the View IDs. Unlike the package mechanism, the IDs of the resources in a project are using one common namespace. Therefore, we have to figure out some ways to name the fields with the same functionality but in different layout files.

我的方法是添加的名词或布局文件的Acitvity类名应用于原始ID前面的动词,由一个点分开。例如,一个ID原名中显示影片的信息可能会成为movie.details.description一个活动说明。

My way is to add the noun or the verb that the layout file's Acitvity class name used in the front of the original ID, separated by a dot. For example,an ID originally named "description" in a Activity displaying a movie's information may become "movie.details.description".

有没有什么更好的想法?

Is there any better ideas?

推荐答案

首先,我用同样的概念,但现在我尝试使用更多通用的标识。在你的情况我就简单地调用ID 说明。所以你并不需要一个id为每个元素,并可以重复使用它们,因为它并不重要的布局你引用,当你调用findViewById(R.id.description)你知道你得到这个布局的描述元素。

First I used the same concept but now I try to use more generic ids. In you case I would simply call the id description. So you don't need an id for each element and can reuse them as it doesn't matter which layout you're referencing when you call findViewById(R.id.description) you know you get the description element of this layout.

当然,你要知道,如果你布局的描述元素的。这可能是不利的。

Of course you have to know if you layout has a description element at all. This might be a disadvantage.

这篇关于什么是你的视图的ID命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆