Android day 4, mysterious seal gift box day 4

Source: Internet
Author: User

Android day 4, mysterious seal gift box day 4

1. TextView is mainly used to display a piece of text information on the interface.

2. A Button control used to interact with users

// Register a listener for the Button click event
Public class Click extends Activity {private Button button; @ Override ptotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); button = (Button) findViewById (R. id. button); button. setOnClickListener (new OnClickListener () {@ Override public void OnClick (View v) {// click logic }});}}

3. EditText allows users to enter and edit content in the control and process the content in the program.

We use EditText and Button to complete some functions. click the Button to obtain the content entered in EditText.

 @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        button = (Button) findViewById(R.id.button);        editText = (EditText) findViewById(R.id.edit);        button.setOnClickListener(new View.OnClickListener(){            @Override            public void onClick(View view) {                String inputText = editText.getText().toString();                Toast.makeText(MainActivity.this, inputText,                        Toast.LENGTH_SHORT).show();            }        });    }

4. ImageView is a widget used to display images on the interface.

Now we can dynamically change the image in ImageView through code in the program.

@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. image); button = (Button) findViewById (R. id. button_img); imageView = (ImageView) findViewById (R. id. image); button. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View view) {imageView. setImageResource (R. drawable. two );}});}
// Change the displayed image to two by calling the setImageResource () method of ImageView.

5. ProgressBar is used to display a progress bar on the interface, indicating that our program is loading some data.

6. AlertDialog a dialog box is displayed on the current interface.

public class ProgressBar extends Activity {    private Button button;    private ProgressBar progressBar;    @Override    protected void onCreate(Bundle savedInstanceState){        super.onCreate(savedInstanceState);        setContentView(R.layout.progressbar);        button = (Button) findViewById(R.id.button_progress);  /*      progressBar = (ProgressBar) findViewById(R.id.progress);*/        button.setOnClickListener( new View.OnClickListener(){            @Override            public void onClick(View view){            }        });    }}

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.