[Learn Android while working on a project] Xiao Bai will encounter problems-Appcompat_V7 and androidappcompat

Source: Internet
Author: User

[Learn Android while working on a project] Xiao Bai will encounter problems-Appcompat_V7 and androidappcompat
Problem description:

The first problem is the selection of the adt version and the sdk version:

Adt according to non-white friends said the election of the latest ADT-22.3.0, and I also updated the sdk to the latest (well, this requires fanqiang, or find offline package ). I'm very happy. I think we can start. So I created an Android project, next --> next... Finish! Project generation! (You must enter something in the middle)



After the project is built, Eclipse automatically generates a strange Appcompat_V7 project. When an Android project is created, an additional appcompat_v7_2 project is created, the "extra Project" in the appcompat_v7_x format will be created in the same way (this occurs after the ADT is upgraded to 22.6.x, but not in versions earlier than 22.3.x ). I looked at Virgo very awkwardly, so I searched Baidu and google and finally found the reason.

Cause:

This problem does not occur before the ADT version 22.3.x. This problem occurs only after the version is upgraded to 22.6.x. You can guess it is caused by the new version. After you guess the source cause, you can analyze the appcompat_v7to use it. Expand the appcompat_v7project and find a readme.txt file. Double-click to view it. The description of this file is as follows:

Library Project including compatibility ActionBar.

This can be used by an Android project to provide
Access to ActionBar on applications running on API 7 +.

There is technically no source, but the src folder isnecessary
To ensure that the build system works.Thecontent is actually
Located in libs/android-support-v7-appcompat.jar.
The accompanying resources must also be encoded in theapplication.


Literally, we can see that this Project is a Library Project, which enables your Android Project to access the ActionBar API in the API7 + sdk version (Android, the ActionBar is equivalent to the operation bar on the user interface. For details about the ActionBar, see http://developer.android.com/guide/topics/ui/actionbar.html. Therefore, we can see that this project is used to be compatible with the sdk of earlier versions.

Solution:

Method 1: Because this project is generated to be compatible with low-speed sdks, you only need to select the lowest version as Android4.0 or above when creating a project;

Method 2: The Code does not appear after adt is updated to 22.6.x, but does not exist in versions before 22.3.x. If yes, discard the new version and switch back to the old version 22.3.x. You can download it to my online storage.

Of course, the problem will not end so easily. Let's talk about it later.

Refer:

Http://blog.sina.com.cn/s/blog_9653ee0f0101jeaf.html



Ladies and gentlemen, I am a beginner in android. I encountered a problem in handler? (See the following code)

First, when the Activity is started, instantiate your handler and execute oncreate to bind the event to your button.
When handler is created, because you added {} to the new Handler and wrote updateThread, in fact, the updateThread you declare is the internal function of your handler. It can only be used in your new handler. Therefore, in your other two classes startlistener and endlistener, you cannot call this updatethread.
You can put the updateTHread statement in the Activity.
In addition, you define the startListener class and then bind the button, which is good, but not good enough. You should define a ButtonListener and then use switch (v. getId ())
{
Case R. id. endBtn: handler. post (updateThread); // do something
Break;
Case R. id. startBtn: handler. removeCallbacks (updateThread); // do something
Break;
Default: // do something
}

In this way, you can instantiate only one listener: ButtonListener bl = new ButtonListener ();
Then startBtn. setOnClickListener (bl); endBtn. setOnClickListener (bl.
Another common practice is to enable your MainActivity implements OnClickListener, and then enable the Activity to implement The onClick event.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.