Как вы инициализируете view элементы?
Здравствуйте!
В работе начал сталкиваться с тем, что на экране очень много разные вьюшек, сложная разметка и т.д. Что-то нужно показывать, что-то прятать и всегда помнить, какая переменная за что отвечает, чтобы по несколько раз не инициализировать. (Использую библиотеку AQuery
вместо findViewById()
.) В итоге у меня выходит вот такой код.
Правильно так делать? Как вы выходите из таких ситуаций?
private void initAllViews() {
emptyList = aq.id(R.id.tv_no_operations_text).getTextView();
statementText = aq.id(R.id.tv_statment_text).getTextView();
statementText.setTypeface(typeface);
btnGetStatement = aq.id(R.id.bt_get_card_receipt).getButton();
btnGetStatement.setTypeface(typeface);
historyPeriod = aq.id(R.id.bankproductHistoryPeriod).getTextView();
bankProductHistoryWeekly = aq.id(R.id.bankproductHistoryWeekly).getTextView();
bankProductHistoryMonth = aq.id(R.id.bankproductHistoryMonth).getTextView();
dateFrom = aq.id(R.id.bankproductDetailsDateFrom).getTextView();
dateTill = aq.id(R.id.bankproductDetailsDateTill).getTextView();
loadingCard = (LinearLayout) aq.id(R.id.ll_loading_card).getView();
datePicker = (LinearLayout) aq.id(R.id.bankproductDetailsWeekPickerFrame).getView();
transferToLayout = (LinearLayout) aq.id(R.id.ll_action_on_card).getView();
transferFromLayout = (LinearLayout) aq.id(R.id.ll_action_from_card).getView();
blockLayout = (LinearLayout) aq.id(R.id.ll_action_block_card).getView();
payFromLayout = (LinearLayout) aq.id(R.id.ll_action_pay_from_card).getView();
infoFrame = (LinearLayout) aq.id(R.id.bankproduct_details_infoFrame).getView();
llRequisites = (LinearLayout) aq.id(R.id.ll_requisites).getView();
actionsFrame = (LinearLayout) aq.id(R.id.bankproduct_details_actionsFrame).getView();
cardBlocked = (LinearLayout) aq.id(R.id.bank_product_details_card_blocked).getView();
creditInformation = (LinearLayout) aq.id(R.id.ll_credit_information).getView();
bankProductInfo = (FrameLayout) aq.id(R.id.bankproduct_info_button_acc).getView();
bankProductActions = (FrameLayout) aq.id(R.id.bankproduct_actions_button).getView();
monthPickerFrame = (FrameLayout) aq.id(R.id.bankproductDetailsMonthPickerFrame).getView();
frameCards = (FrameLayout) aq.id(R.id.frame_cards).getView();
frameRefreshCards = (FrameLayout) aq.id(R.id.frame_refresh_cards).getView();
frameProductDetails = (FrameLayout) aq.id(R.id.frame_product_details).getView();
actionsText = aq.id(R.id.bankproduct_actions_text_acc).getTextView();
infoText = aq.id(R.id.bankproduct_info_text_acc).getTextView();
actionsSelected = aq.id(R.id.bankproduct_actions_selected).getView();
infoSelected = aq.id(R.id.bankproduct_info_selected_acc).getView();
progressBar = aq.id(R.id.progress_cards_receipt).getProgressBar();
progressBarCards = aq.id(R.id.progress_cards).getProgressBar();
refreshCardStatement = aq.id(R.id.iv_refresh_card_receipt).getImageView();
errorText = aq.id(R.id.tv_error_text).getTextView();
}
Источник: Stack Overflow на русском