Android andbase framework internally encapsulates the implementation progress box, toast box, pop-up box and confirmation box (II)

This is the second note for learning and sorting out the andbase framework. Friends who want to understand the andbase framework can read this article and learn together.

Use the method encapsulated inside abactivity to realize the progress box, toast box, pop-up box and confirmation box

Abactivity in andbase encapsulates many methods for us to use, which makes it more convenient to use. We only need to pass relevant parameters.. we don't need to use basic functions for construction

Just like the progress box, toast box, pop-up box and confirmation box... These basic things are encapsulated in the abactivity of andbase... We only need to pass parameters and call the internal methods to create these views... Whether it is the call of the progress bar, toast box, pop-up box and confirmation box (the confirmation box is basically similar to the pop-up box), It's just that the confirmation box has more related controls than the pop-up box. The pop-up box is generally used to directly pop up a piece of text information, while the confirmation box also needs to add related buttons... In short, the calling method is very simple

Here we can see that we can complete the creation of these basic views by calling relevant methods and passing relevant parameters... Which makes our operation more convenient

The previous toast information pop-up box is called:

Toast. Maketext (getapplicationcontext(), "information to be displayed", toast. Length). Show(); This is the way it is now:

Showtoast ("information to be displayed");

In this way, the toast information box can be displayed directly.. we may not agree with such a simple encapsulation.. but what if it is more code? Take our confirmation pop-up box for example... If we write a confirmation pop-up box in the previous activity, we need to rewrite it manually... The following is a handwritten confirmation box based on the activity

Use the andbase framework to call functions, which makes the process very simple.. we only need to pass relevant parameters to call methods... The effect of calling this function is the same as the above writing method, and we don't need to set dialog. Disass(); As long as you click the button, the pop-up box will disappear... The onclick method here is the operation to be performed after the pop-up box disappears... In contrast, using the framework simplifies the amount of code

In fact, these simple views are still very simple... Although it seems that the amount of code is not reduced very much, for more complex operations... The optimized methods in the framework are still very easy to use... That is, they reduce the redundancy of code and realize more functions

Let's take a look at the implementation process of the source code

The source code implementation process of toast box... We can see that the methods in the framework encapsulate the original methods. We can directly use toast box by passing relevant parameters... In fact, there is the source code of showtoast inthread() in the source code.. by opening a new thread

The source code implementation process of the progress box... The source code is very simple... We only need to call these two methods when using a progress bar

I won't paste the source code of the pop-up box, because the source code is written a little more... Here we just paste the packaging method

The dialog box displayed by this method is an information pop-up box without a button. It only prompts information... ID sets the display position of the pop-up box... View indicates the view to be displayed... So a pop-up box is created to display at the specified position

Public void ShowDialog (int ID, view view) {} during the execution of the above method, setdialoglayoutparams() function will be called to set relevant properties and parameters of pop-up box layout, that is, a setting of how pop-up boxes can be better displayed on the screen

This is the calling process of the source code. It doesn't seem difficult to understand

The pop-up box of this method is a confirmation box with buttons. Title and MSG represent the title content and prompt content of the dialog box... And the transmission of listening events when clicking the confirmation button

Public void ShowDialog (string title, string MSG, dialoginterface. Onclicklistener mokonclicklistener) {} the only difference between the pop-up box of this method and the above is that the content of the pop-up box is not the specified string, but a view we define

Public alertdialog ShowDialog (string title, view view, dialoginterface. Onclicklistener mokonclicklistener) {} the pop-up boxes are basically these modes... The implementation of the source code is very simple... The principle is some encapsulation of those basic functions... The rest are not pasted... Everything changes.

The above is the whole content of this article. I hope it will be helpful to your study.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>