The fourth day of Android Learning to supplement--android's common controls

Source: Internet
Author: User

(Transferred from: http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html)

The fourth day of Android Learning to supplement--android's common controls

Familiar with the use of several commonly used Android control methods:

One, Radiogroup and radiobutton--radio buttons

Second, checkbox--check box

Three, toast--prompt box, will automatically disappear

Iv. progressbar--progress Bar Tool

V. listview--display the control as a list

Here is a detailed explanation of these things:

First of all, we should note that it is not necessary to declare a control in a layout file, and we can make a control declaration in the activity when we need to dynamically generate some controls in the future, which we will introduce later in the project.

    • Let's first look at the use of Radiogroup and RadioButton.

First look at Radiogroup and RadioButton in the Main.xml declaration, such as the code:

Here the Radiogroup and checkbox set the listener differently from the button, using an anonymous inner class that invokes the callback function to implement the settings for the listener of the radio and checkbox.

If the code is to add a listener for Radiogroup:

    • Let's see how the checkbox is used.

Let's take a look at the declaration of the checkbox in Main.xml, as in code:

If the code is to add a listener to the checkbox:

    • Use of ProgressBar

The following code is the declaration method for the horizontal progress bar:

The Declaration method for the default progress bar:

As you can see, the Style property's setting determines how the progress bar will look.

The following code is the activity class that implements the two progress bars--progressbartest.java

Package mickey.progress;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ProgressBar;


public class Progressbartest extends Activity {

declaring variables
Private ProgressBar first = null;
Private ProgressBar second = null;
Private button button = null;
private int i = 0;

@Override
public void OnCreate (Bundle savedinstancestate) {
These two sentences generally have to be
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Get control objects by Findviewbyid
First = (ProgressBar) Findviewbyid (R.id.first);
Second = (ProgressBar) Findviewbyid (R.id.second);
Button = (button) Findviewbyid (R.id.button);
Set Listener for button
Button.setonclicklistener (New Buttonlistener ());
}

Listener Inner Class
Class Buttonlistener implements Onclicklistener {
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
if (i = = 0) {
Set the progress bar is visible, if write 0, do not look good, view.visible can let a person see is set as visible
First.setvisibility (view.visible);
Second.setvisibility (view.visible);
} else if (I < First.getmax ()) {

Set the maximum value of the progress bar
First.setmax (200);
Set the position of the progress bar
First.setprogress (i);

Set the position of the second progress bar
First.setsecondaryprogress (i + 10);

Because the default progress bar is unable to display the status of the second, it does not have to be set

} else {
First.setvisibility (View.gone);
Second.setvisibility (View.gone);
}
i = i + 10;
}
}
}

As the result of the run:

However, in the development of applications, such as the download of these features can not be written in the activity, it may lead to the entire activity for a long time without response or error, the user experience is poor, so handler will come into being.

In the example of using the ListView, it is important to note that the subclass listactivity of activity is inherited here.

The fourth day of Android Learning to supplement--android's Common controls (go)

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.