亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android 中CheckBox的isChecked的使用實(shí)例詳解

 更新時(shí)間:2017年04月21日 15:16:59   投稿:lqh  
這篇文章主要介紹了Android 中CheckBox的isChecked的使用實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

Android 中CheckBox的isChecked的使用實(shí)例詳解

范例說(shuō)明

所有的網(wǎng)絡(luò)服務(wù)在User使用之前,都需要簽署同意條款,在手機(jī)應(yīng)用程序、手機(jī)游戲的設(shè)計(jì)經(jīng)驗(yàn)中,??匆?jiàn)CheckBox在同意條款情境的運(yùn)用,其選取的狀態(tài)有兩種即isChecked=true與isChecked=false。

以下范例將設(shè)計(jì)一個(gè)TextView放入條款文字,在下方配置一個(gè)CheckBox Widget作為選取項(xiàng),通過(guò)Button.onClickListener按鈕事件處理,取得User同意條款的狀態(tài)。

當(dāng)CheckBox.isChecked為true,更改TextView的文字內(nèi)容為“你已接受同意!!”,當(dāng)未選取CheckBox時(shí),Button則不可以被選擇的(被Disabled)。

范例程序

src/irdc.ex04_04/EX04_04.java

利用CheckBox.OnClickListener里的事件來(lái)判斷Button該不該顯示,其方法就是判斷Button.Enabled的值;在一開(kāi)始時(shí),默認(rèn)參數(shù)為false,當(dāng)有單擊CheckBox時(shí),Button參數(shù)就修改為true。

/* import程序略 */

 

public class EX04_04 extends Activity

{

 /** Called when the activity is first created. */

 

 /*聲明 TextView、CheckBox、Button對(duì)象*/

 public TextView myTextView1;

 public TextView myTextView2;

 public CheckBox myCheckBox;

 public Button myButton;

 

 @Override

 public void onCreate(Bundle savedInstanceState)

 {

 super.onCreate(savedInstanceState);

 setContentView(R.layout.main);

 

 /*取得TextView、CheckBox、Button*/

 myTextView1 = (TextView) findViewById(R.id.myTextView1);

 myTextView2 = (TextView) findViewById(R.id.myTextView2);

 myCheckBox = (CheckBox) findViewById(R.id.myCheckBox);

 myButton = (Button) findViewById(R.id.myButton);

 

 /*將CheckBox、Button默認(rèn)為未選擇狀態(tài)*/

 myCheckBox.setChecked(false);

 myButton.setEnabled(false);

 

 myCheckBox.setOnClickListener(new CheckBox.OnClickListener()

 {

  @Override

  public void onClick(View v)

  {

  // TODO Auto-generated method stub

  if(myCheckBox.isChecked())

  {

   /*設(shè)置Button為不能選擇對(duì)象*/

   myButton.setEnabled(true);

   myTextView2.setText("");

  }

  else

  {

   /*設(shè)置Button為可以選擇對(duì)象*/

   myButton.setEnabled(false);

   myTextView1.setText(R.string.text1);

   /*在TextView2里顯示出"請(qǐng)勾選我同意"*/

   myTextView2.setText(R.string.no);   

  }

  }

 });

  

 myButton.setOnClickListener(new Button.OnClickListener()

 {

  // 程序略

  });

 

 }

}

擴(kuò)展學(xué)習(xí)

CheckBox在默認(rèn)內(nèi)容為空白時(shí)(沒(méi)有任何默認(rèn)的提示文字下),可設(shè)置提示User的文字,其調(diào)用的方法為CheckBox.setHint()方法;在擴(kuò)展學(xué)習(xí)的范例練習(xí),是抓取R.string.hello這個(gè)字符串常數(shù),其與默認(rèn)CheckBox文字的結(jié)果是相同的,你不妨試試看。

 

myTextView1 = (TextView) findViewById(R.id.myTextView1);

myTextView2 = (TextView) findViewById(R.id.myTextView2);

myCheckBox = (CheckBox) findViewById(R.id.myCheckBox);

myButton = (Button) findViewById(R.id.myButton);

myCheckBox.setChecked(false);

 

/*利用setHIT抓取strings里面的值*/

CharSequence hint = getString(R.string.hello);

myCheckBox.setHint(hint);

 

/*設(shè)置文字顏色*/

myCheckBox.setHintTextColor(Color.RED);

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論