在Android Studio中是否有一个自动生成给定类中的getter和setter的快捷方式?


当前回答

以防有人使用Eclipse

Windows 8.1操作系统| Eclipse Idle Luna

声明顶级变量私有字符串用户名Eclipse在屏幕左侧生成一个警告,单击该警告,会显示一些建议,然后选择generate。

其他回答

使用code=>generate=>getter()和setter()对话框,选择所有变量,一次性生成所有getter(),setter()方法。

在编辑器中使用Alt+ Insert (Windows)或Command+ N (Mac),您可以轻松地为类的任何字段生成getter和setter方法。这与使用菜单栏->代码->生成…

然后使用shift或control按钮,选择所有你需要添加getter和setter的变量

Android Studio & OSx:

按cmd+n >生成> Getter和Setter

Android Studio和Windows:

按Alt +插入>生成> Getter和Setter

右键单击编辑器,然后选择源->生成getter和setter或按Alt + Shift + S

你可以使用Android Studio的AndroidAccessors Plugin来生成getter和setter,而不需要m作为方法的前缀

例:中期; 将生成getId()和setId()而不是getmId()和setmId()