标签:Toast CheckBox cb private 复选框 import android
XML
文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/first_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选项1" />
<CheckBox
android:id="@+id/secend_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选项2" />
<CheckBox
android:id="@+id/third_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选项3" />
</LinearLayout>
Java
文件如下:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private CheckBox cb_one;
private CheckBox cb_two;
private CheckBox cb_three;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cb_one = (CheckBox) findViewById(R.id.first_checkbox);
cb_two = (CheckBox) findViewById(R.id.secend_checkbox);
cb_three = (CheckBox) findViewById(R.id.third_checkbox);
cb_one.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (cb_one.isChecked()) {
Toast.makeText(MainActivity.this, cb_one.getText(), Toast.LENGTH_SHORT).show();
}
}
});
}
}
标签:Toast,CheckBox,cb,private,复选框,import,android 来源: https://blog.csdn.net/fukangwei_lite/article/details/117808965
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。