Android CheckBox應用實例

下面爲實例代碼:

private CheckBox location;

		location = (CheckBox)findViewById(R.id.location); 
		location.setTextColor(Color.BLACK);
		location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				// TODO Auto-generated method stub
				  
				// 判斷當前checkbox的狀態,是否選中
				if(location.isChecked()){
				
				Toast.makeText(Sendmessage.this,"已選中checkbox",Toast.LENGTH_LONG).show();  
				// 將checkbox設置爲未選中狀態
                                location.setChecked(false);
	
				}else{
					
                                Toast.makeText(Sendmessage.this,"未選中checkbox",Toast.LENGTH_LONG).show();  
                                // 將checkbox設置爲選中狀態
                                location.setChecked(true);
				
				}
			}
		});

大笑!!!!!!!!!!!!!!!!!!!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章