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

写了几个基本控件

  • Button
  • ImageButton
  • EditText
  • CheckBox
  • RadioGroup和RadioButton
  • ToggleButton
下面是代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">

  <Button
   android:text="Button" 
   android:id="@+id/button1"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </Button>
 <ImageButton 
    android:text="ImageButton" 
    android:id="@+id/buttonimage" 
    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/icon">
     </ImageButton>
     
     <EditText
     android:id="@+id/edit1"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     />
     <CheckBox
     android:id="@+id/check1"
   android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:text="Autosave"
     />
  <CheckBox
  android:id="@+id/checkstar"
  style="?android:attr/starStyle"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  />
  <RadioGroup
  android:id="@+id/grou1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  >
  <RadioButton
  android:id="@+id/radio1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="option1"
  > 
  
  </RadioButton>
  <RatingBar
  android:id="@+id/ra1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:numStars="4"
  android:rating="2"
  >
  </RatingBar>
  
  </RadioGroup>
  
  <ToggleButton
  android:id="@+id/toggole1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  ></ToggleButton>
</LinearLayout>

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

      
    }

 
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值