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){ } }); }}