亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

代碼和老師一樣,出現停止運行

package com.ab.eat;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ToggleButton;
import android.os.Build;

public class MainActivity extends ActionBarActivity {
?? ?private CheckBox checkbox;
??? @Override
??? protected void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.activity_main);
//?????? 初始化checkbox
??????? checkbox=(CheckBox) findViewById(R.id.checkbox);
//??????? 通過設置checkbox的監聽事件來對checkbox進行處理,看是否被選中
??????? checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
?? ??? ??? ?
?? ??? ??? ?@Override
?? ??? ??? ?public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//?? ??? ??? ??? ?通過onCheckedChanged來監聽CheckBox是否被選中
?? ??? ??? ??? ?String text=checkbox.getText().toString();
?? ??? ??? ??? ?if(isChecked){
?? ??? ??? ??? ??? ?//獲得CheckBox的文本內容
?? ??? ??? ??? ??? ?Log.i("tag", text);
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?});
?? ?}
}



<CheckBox
??????? android:checked="false"
??????? android:id="@+id/checkBox1"
??????? android:layout_width="wrap_content"
??????? android:layout_height="wrap_content"
??????? android:text="籃球" />

正在回答

1 回答

public class MainActivity extends ActionBarActivity {
?? ?private CheckBox checkbox;
??? @Override
??? protected void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.activity_main);
//?????? 初始化checkbox
??????? checkbox=(CheckBox) findViewById(R.id.checkbox);
//??????? 通過設置checkbox的監聽事件來對checkbox進行處理,看是否被選中
??????? checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
?? ??? ??? ?
?? ??? ??? ?@Override
?? ??? ??? ?public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//?? ??? ??? ??? ?通過onCheckedChanged來監聽CheckBox是否被選中
?? ??? ??? ??? ?String text=checkbox.getText().toString();
?? ??? ??? ??? ?if(isChecked){
?? ??? ??? ??? ??? ?//獲得CheckBox的文本內容
?? ??? ??? ??? ??? ?Log.i("tag", text);
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?});
?? ?}
}


把加粗下劃線部分改為“Activity”

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android攻城獅的第一門課(入門篇)
  • 參與學習       312517    人
  • 解答問題       4931    個

想快速掌握Android應用開發基礎,選擇學習這門課程就對了。

進入課程

代碼和老師一樣,出現停止運行

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號