android整合--UI基本控件Button,ImageButton,EditText,ChcekBox,ToggleButton,RadioButton

写了几个基本控件

  • Button
  • ImageButton
  • EditText
  • CheckBox
  • RadioGroup和RadioButton
  • ToggleButton
下面是代码



  
 
     
     
     
     
  
  
   
  
  
  
  
  
  
  
  


activity使用
public class CreateUi extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.baseui);
            
            CheckBox che = (CheckBox)findViewById(R.id.check1);
            che.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if(((CheckBox)v).isChecked())
					Toast.makeText(getBaseContext(),  
		                    " was clicked",  
		                    Toast.LENGTH_LONG).show();  
					else 
					Toast.makeText(getBaseContext(),  
			                    " was not clicked",  
			                    Toast.LENGTH_LONG).show();  	
				}
			});
            RadioGroup rg = (RadioGroup)findViewById(R.id.grou1);
            rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(RadioGroup group, int checkedId) {
					// TODO Auto-generated method stub
					RadioButton radio = (RadioButton)findViewById(R.id.radio1);
					if(checkedId==radio.getId()){
						Toast.makeText(getBaseContext(),  
			                    " option1 was  clicked",  
			                    Toast.LENGTH_LONG).show();  	
					}
				}
			});
            
            ToggleButton toggle = (ToggleButton)findViewById(R.id.toggole1);
            toggle.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if(((ToggleButton)v).isChecked()){
						Toast.makeText(getBaseContext(),  
			                    " toggle1 was  clicked",  
			                    Toast.LENGTH_LONG).show(); }
						else {
							Toast.makeText(getBaseContext(),  
									((ToggleButton)v).getText()+  " toggle1 was  clicked",  
				                    Toast.LENGTH_LONG).show(); 
						}
				
					}
				
			});

      
    }

 
}



你可能感兴趣的:(android)