Organizing your Source File

Android應(yīng)用應(yīng)該使用被以一種簡潔的文件結(jié)構(gòu)組織,使你的代碼更容易閱讀。此外,合理的代碼以及類命名規(guī)則是非常重要的,以確保你的代碼整潔易于維護


Naming Convention

Java Code

Type Example Description
Variable incomeTaxRate All variables should be camel case
Constant DAYS_IN_WEEK All contants should be all uppercase
Method convertToEuroDollars All methods should be camel case
Parameter depositAmount All parameter names should be camel case

For Android Classes

Name Convention Inherits
Activity CreateTodoItemActivity AppCompatActivity,Activity
List Adapter TodoItemsAdapter BaseAdapter,ArrayAdapter
Database Helper TodoItemsDbHelper SQLiteOpenHelper
Network Client TodoItemsClient N/A
Fragment TodoItemDetailFragment Fragment
Service FetchTodoItemService Service,IntentService

Android Folder Structure

  • com.example.myapp.activities - 包含所有的activities
  • com.example.myapp.adapters - 包含所有基本的adapter
  • com.example.myapp.models - 包含所有的數(shù)據(jù)模型
  • com.example.myapp.network - 包含所有的網(wǎng)絡(luò)代碼
  • com.example.myapp.fragments - 包含所有的fragment
  • com.example.myapp.utils - 包含有的幫助代碼
  • com.example.myapp.interfaces - 包含所有的接口
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容