Layout: Layout/activity_main.xml
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<textview
Android:id= "@+id/tv"
android:text= "Click to change Font Color"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:clickable= "true"
/>
<imageview
Android:id= "@+id/iv"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:src= "@drawable/ic_launcher"
/>
<radiogroup
Android:id= "@+id/rg"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal" >
<radiobutton
Android:id= "@+id/rbmale"
android:text= "Male"
Android:checked= "true"
/>
<radiobutton
Android:id= "@+id/rbfamale"
android:text= "female"/>
<checkbox
Android:id= "@+id/cbmale"
android:text= "Change male"/>
<checkbox
Android:id= "@+id/cbfamale"
android:text= "Change female"/>
</RadioGroup>
</LinearLayout>
Java class:
Package com.example.day03_01;
Import android.support.v7.app.ActionBarActivity;
Import Android.graphics.Color;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.CheckBox;
Import Android.widget.ImageView;
Import Android.widget.RadioButton;
Import Android.widget.RadioGroup;
Import Android.widget.RadioGroup.OnCheckedChangeListener;
Import Android.widget.TextView;
public class Mainactivity extends Actionbaractivity {
Private RadioButton Rbmale;//Initialize-----male
Private RadioButton Rbfamale;//Initialize------female
Private Radiogroup RG;
Private TextView TV;
Private ImageView IV;
Private CheckBox Cbmale;
Private CheckBox Cbfamale;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Init ();
Setlistener ();
}
private void Setlistener () {
TODO auto-generated Method Stub
Cbmale.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
Rbmale.setchecked ((CheckBox) view). isChecked ());
Rbfamale.setchecked (! ( (CheckBox) view). isChecked ());
}
});
Cbfamale.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (view view) {
Rbmale.setchecked (! ( (CheckBox) view). isChecked ());
Rbfamale.setchecked ((CheckBox) view). isChecked ());
}
});
Tv.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
TextView TV = (TextView) view;
Tv.settextcolor (color.red);
}
});
Iv.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
ImageView IV = (ImageView) view;
Iv.setimageresource (R.DRAWABLE.P01);
}
});
}
private void Init () {//Initialize----male, female
Rbmale = (RadioButton) Findviewbyid (R.id.rbmale);
Rbfamale = (RadioButton) Findviewbyid (R.id.rbfamale);
RG = (Radiogroup) Findviewbyid (R.ID.RG);
TV = (TextView) Findviewbyid (r.id.tv);
IV = (ImageView) Findviewbyid (R.ID.IV);
Cbmale = (CheckBox) Findviewbyid (R.id.cbmale);
Cbfamale = (CheckBox) Findviewbyid (R.id.cbfamale);
}
}
Effect:
650) this.width=650; "src=" http://img.blog.csdn.net/20141122145343734 "/>
This article from "Follow the heart of the other Side" blog, reproduced please contact the author!
Android implementation of individual components click event Monitoring