Some tips for using KJFrameForAndroid

KJFrameForAndroid usage method 1

Summary

Write to those who are using, want to use, and haven't used KJFrame yet. KJFrameForAndroid is divided into four functions: Activity inheritance chain specification, Http data request and upload and download, Bitmap large image loading and only loading memory images when ListView scrolls, database object storage and collection object storage. There is also an independent function CJFrame plug-in development framework that supports launching apk applications that are not installed in your mobile phone.
This article is original, please indicate the address for reprint: http://blog.kymjs.com/

Activity inheritance chain

Use your Activity (Fragment) to inherit from KJActivity (KJFragment). In normal development, we often write the methods of data initialization, findview, property setting of controls, etc. in an onCreate(), which will cause the onCreate method to be too bloated, and use the base class Activity (Fragment) of the KJFrame module. This problem can be easily solved.

  • The calling sequence of each method in the base class: 
setRootView(); //Used to call setContent();  
@BindView //setRootView will execute annotation binding after execution  
initDataFromThread(); (executed asynchronously for time-consuming operations)   
threadDataInited(); (it will be called back after initDataFromThread() is executed)   
initData(); // used to initialize data  
initWidget(); // used to set the control content  
registerBroadcast(); //Used to register broadcast and context menu 
 
  • Annotative binding of controls and setting listeners Using UILibrary, you can complete the findview of the control and set the click event with just one line of code, just like the example below, just add the @BindView annotation to achieve it.
@BindView(id = R.id.xxx, click = true);  
private Button btn;  
 

This is equivalent to calling 

private Button btn;   
btn = findViewById(R.id.xxx);  
btn.setOnClickListener(this); 
 

Of course, it is up to you to decide whether you must set the click event. If you don't set it, then you don't need to write click=true.

  • ViewInject function and Toast optimization Every time you write a Toast, you have to write a long list of codes, which is very troublesome. Then KJFrame encapsulates Toast in a very humanized way, you only need to call
ViewInject.toast("Injection text");  
 

At the same time, ViewInject also encapsulates commonly used pop-up dialog boxes. 

/ / Pop up a selection pop-up window, and has an overloaded method,  
//You can customize the listener for clicking the OK button and the content text of the pop-up window
getExitDialog(Context context); 
getDateDialog(String title, TextView textView)
 
  • Free usage If there is no way to inherit the base class of KJFrame due to project restrictions, then you can still use annotation binding and toast optimization, but the usage is slightly different. If you do not inherit the base class, you need to manually call after the Activity's setContent() method when using the annotation @BindView
AnnotateUtil.initBindView(this);  
 

When Toast is used, since the framework base class is not inherited, you need to manually pass in the Context object 

ViewInject.toast(this, "Injection text"); 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326810574&siteId=291194637