Android Basic Controls use

Source: Internet
Author: User

// Auto-Padded TextView

Autocompletetextview mplace = (autocompletetextview) Findviewbyid (R.ID.AUTOCOMPLETETEXTVIEW1);

string[] books = new string[] {"Rollen", "Allen", "Rollenren", "roll"};


// define an adapter for raw data first

Arrayadapteradapter =new arrayadapter<string>

(mainactivity.this,android. R.layout.simple_dropdown_item_1line,books);


// Set the TextView Adapter

Mplace.setadapter (adapter);


// Enter multiple auto- TextView

Multiautocompletetextviewmtexts = (Multiautocompletetextview) Findviewbyid (R.ID.MULTIAUTOCOMPLETETEXTVIEW1);


// Set the TextView Adapter

Mtexts.setadapter (newarrayadapter<string>

(Mainactivity.this,android. R.layout.simple_dropdown_item_1line,books));


// Set the adapter's separator, such as comma

Mtexts.settokenizer (Newmultiautocompletetextview.commatokenizer ());


// limit the length of characters entered

Finaledittext text_filterred = (EditText) Findviewbyid (R.ID.EDITTEXT1);

Text_filterred.setfilters (newinputfilter[]{

newinputfilter.allcaps (),

Newinputfilter.lengthfilter (2)

});


//button button to implement Activity Jump Pass Parameters

Finalbutton btn = (Button) Findviewbyid (R.id.button1);

Btn.setonclicklistener (Newonclicklistener () {

@Override

publicvoid OnClick (View v) {

intentintent = new Intent ();

Intent.setclass (mainactivity.this,test1activity.class);

Intent.putextra ("str", "come from First activity");

startactivity (intent);

}

});

//checkbox Settings and Response events

Finalcheckbox Check_button = (CheckBox) Findviewbyid (r.id.checkbox1);

Check_button.setonclicklistener (Newonclicklistener () {

@Override

publicvoid OnClick (View v) {

Tx.settext (check_button.ischecked ()? " Selected ":" unchecked ");

}

});

//togglebutton Settings and Response events

Finaltogglebutton ToggleButton = (ToggleButton) Findviewbyid (R.id.togglebutton1);

Togglebutton.setoncheckedchangelistener (Newoncheckedchangelistener () {

@Override

publicvoid oncheckedchanged (Compoundbutton buttonview,boolean isChecked) {

tx.settext (isChecked? " ) Selected ":" unchecked ");

}

});

// radio button radiogroup settings and Response events

Finalradiogroup Group = (radiogroup) Findviewbyid (r.id.radiogroup1);


// Clear Selection

Group.clearcheck ();

Group.setoncheckedchangelistener (Newradiogroup.oncheckedchangelistener () {

@Override

publicvoid oncheckedchanged (radiogroup Group, int checkedid) {

if (checkedid!=-1) {

RADIOBUTTONRB = (RadioButton) Findviewbyid (checkedid);

if (rb!=null) {

Tx.settext ("Youchose:" +rb.gettext ());

}

}

}

});

// drop-down list Spinner settings and Response events

<spinner

android:id= "@+id/spinner1"

android:layout_width= "Match_parent"

android:layout_height= "Wrap_content"

android:entries= "@array/colors"

android:prompt= "@string/spin_prompt"/>


Use the contents of the array to specify the Spinner data source


Spin= (Spinner) Findviewbyid (r.id.spinner1);

Spin.setonitemselectedlistener (Newonitemselectedlistener () {

@Override

publicvoid onitemselected (adapterview<?> arg0, View arg1,

intarg2, Long Arg3) {

textviewtvn= (TextView) arg1;// get the TextView

if (tvn!=null) {

Tx.settext (Tvn.gettext (). toString ());

}

}

@Override

publicvoid onnothingselected (adapterview<?> arg0) {

//todo auto-generated Method Stub

}

});

Android Basic Controls use

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.