diff --git a/frameworks/components/text_adapter.cpp b/frameworks/components/text_adapter.cpp index 3df75ff27349c29ced2d61d28663b6f7ece69abe..1297bee645f4b4b4c98c53d2d7aa0f9050f00afb 100755 --- a/frameworks/components/text_adapter.cpp +++ b/frameworks/components/text_adapter.cpp @@ -103,13 +103,7 @@ UILabel* TextAdapter::GetDynamicText(UIView* inView, int16_t index) for (int16_t i = 0; i < index; i++) { node = node->next_; } - UILabel* newView = nullptr; - if (inView == nullptr) { - newView = new UILabel(); - } else { - newView = static_cast(inView); - } - + UILabel* newView = CreateUILabel(inView); if (newView != nullptr) { newView->SetText(node->data_); if (fontName_ == nullptr) { @@ -127,13 +121,7 @@ UILabel* TextAdapter::GetIntegerText(UIView* inView, int16_t index) if ((index < 0) || ((integerTextEnd_ - integerTextStart_) < index)) { return nullptr; } - UILabel* newView = nullptr; - if (inView == nullptr) { - newView = new UILabel(); - } else { - newView = static_cast(inView); - } - + UILabel* newView = CreateUILabel(inView); if (newView != nullptr) { char buf[BUF_LEN] = {0}; if (formatter_ != nullptr) { @@ -166,6 +154,14 @@ UILabel* TextAdapter::GetIntegerText(UIView* inView, int16_t index) return newView; } +UILabel* TextAdapter::CreateUILabel(UIView* inView) +{ + if (inView == nullptr) { + return new UILabel(); + } + return static_cast(inView); +} + void TextAdapter::ClearDynamicText() { ListNode* node = dynamicText_.Begin(); diff --git a/interfaces/kits/components/text_adapter.h b/interfaces/kits/components/text_adapter.h index d3c486c7bbdf64578296247f2346cee363135e49..9000d6e33beb3d1b58ce9b35fb1348c0ba451a80 100755 --- a/interfaces/kits/components/text_adapter.h +++ b/interfaces/kits/components/text_adapter.h @@ -256,6 +256,7 @@ public: protected: virtual UILabel* GetTextView(UIView* inView, int16_t index); + virtual UILabel* CreateUILabel(UIView* inView); uint8_t dataMode_; private: