1. layout file naming cannot contain uppercase letters, special characters. myimageview.xml error.
2. Meaning of the Simpleadapter adapter parameter:
3. GridView
Three important attributes of the GridView:
4. Global access to Context tips
In the development of Android, a lot of places have to use the context of this class object, such as: the need to pop up a toast, the need to start the event, the need to send the broadcast, the operation of the database when needed, the use of notifications when needed.
If it is in activity, then it is easy to get the context object, because the activity itself inherits the context, and it is available directly. But for more complex logic, the code is not in the activity, so getting the context is not that easy.
Here's a tip to tell you:
Android provides a application class that automatically initializes the class whenever the application starts. And we can customize a application class to make it easier to manage some of the global state information in the program, such as the global context.
1, create a new class MyApplication inherit application.
Package com.example.networktest;
Public class MyApplication extends application {
private static context context;
@Override
Public void OnCreate () {
context = Getapplicationcontext ();
}
Public static Context GetContext () {
return context;
}
}
2, you can specify it under the <application> tab of the Androidmanifest.xml file, as shown in the code below:
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="Com.example.networktest"
- android:versioncode="1"
- Android:versionname="1.0" >
- ......
- <application
- Android:name="Com.example.networktest.MyApplication"
- ...... >
- ......
- </Application>
- </manifest>
Note: Be sure to add the full package name when specifying MyApplication, or the system will not be able to find this class.
So that we have implemented a global access to the context of the mechanism, after no matter you want to be anywhere in the project
Using Context, you just need to call Myapplication.getcontext ().
5.Handler relationship with Looper, message android asynchronous load frame: Handler+looper+message
Summary: Handler is responsible for sending messages, Looper is responsible for receiving handler sent messages, and directly to the message back to handler himself.
MessageQueue is a container for storing messages.
6. The transfer between the main thread and the sub-thread needs to use the Setmessage in handler
If you want to update the UI thread in a child thread, you can use Handler.post (runnable);
Activity classes and non-activity classes, such as adapter Baseadapter classes, can be passed activity.this by means of a transitive construction method; Such as:
Mimgadapter = new Imageadapter (this, Mimgs,
Mcurrentdir.getabsolutepath ());//absolute path to the current folder
Public Imageadapter (context context, list<string> Mdatas, String dirpath) {
This.mdirpath = dirpath;//Parent Path
This.mimgpaths = mdatas;//All pictures
Minflater = Layoutinflater.from (context);
This.context = context;
Mselectedimg.clear ();
}
Android needs to know small details