各种按钮按下并显示消息

1、Button 

   public void buttonClicked(){
    //按钮按下消息窗弹出成功
    setContentView(R.layout.activity_button_clicked_android_main);
    final Button basic_button = (Button) findViewById(R.id.button1);
    basic_button.setOnClickListener(new View.OnClickListener() {
   
    public void onClick(View v) {
    // TODO Auto-generated method stub
    Toast.makeText(ButtonClickedAndroidMainActivity.this, "Button Clicked", Toast.LENGTH_SHORT).show();
    }
    });

    }

 
 
 
2、CheckedBox
 
   public void checkBoxClicked(){
    final CheckBox check_button = (CheckBox) findViewById(R.id.checkBox1);
    check_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv = (TextView) findViewById(R.id.checkBox1);
tv.setText(check_button.isChecked() ? 
"This option is checked" : 
"This option is not checked");
}
});
    }

 
3、radioButton:
    public void radioButton() {
     final RadioGroup group = (RadioGroup)findViewById(R.id.radioGroup1);
     final TextView tv = (TextView)findViewById(R.id.textView1);
     group.setOnCheckedChangeListener(new
      RadioGroup.OnCheckedChangeListener() {
   
   public void onCheckedChanged(RadioGroup group, int checkedId) {
    // TODO Auto-generated method stub
    if(checkedId != -1){
     RadioButton rb = (RadioButton) findViewById(checkedId);
     if(rb != null){
      tv.setText("You choose: " + rb.getText());
     }else {
      tv.setText("Choose 2");
     }
    }
   }
  });
    }
 
 
4、清除选择
 
    public void clearRadioButton(){
     final Button clear_choice = (Button) findViewById(R.id.button2);
     clear_choice.setOnClickListener(new View.OnClickListener() {
   
   public void onClick(View v) {
    // TODO Auto-generated method stub
    RadioGroup group = (RadioGroup) findViewById(R.id.radioGroup1);
    if(group != null){
     group.clearCheck();
    }
   }
  });
    }
void CTestDlg::ReadIniInform()// 读取配置文件 { CString strPath; char tmpstr[120] = {0}; strPath = GetINIPath(); if (GetFileAttributes(strPath) == -1) { return; } memset(tmpstr, 0,120); ::GetPrivateProfileString("设置","频谱仪起始频率" ,NULL, tmpstr,MAX_PATH,strPath); startfreq=atof(tmpstr); memset(tmpstr, 0,120); ::GetPrivateProfileString("设置","频谱仪终止频率" ,NULL, tmpstr,MAX_PATH,strPath); stopfreq=atof(tmpstr); memset(tmpstr, 0,120); ::GetPrivateProfileString("设置","频谱仪频率步进" ,NULL, tmpstr,MAX_PATH,strPath); stepfreq=atof(tmpstr); memset(tmpstr, 0,120); ::GetPrivateProfileString("设置","信号源频率" ,NULL, tmpstr,MAX_PATH,strPath); xhyfreq=atof(tmpstr); memset(tmpstr, 0,120); ::GetPrivateProfileString("设置","信号源功率" ,NULL, tmpstr,MAX_PATH,strPath); xhyamp=atof(tmpstr); memset(tmpstr, 0,120); ::GetPrivateProfileString("设置","信号源VISA地址" ,NULL, tmpstr,MAX_PATH,strPath); XHYvisa=tmpstr; memset(tmpstr, 0,120); ::GetPrivateProfileString("设置","频谱仪VISA地址" ,NULL, tmpstr,MAX_PATH,strPath); PPYvisa=tmpstr; } void CTestDlg::WriteDataToWnd() { CString temp; temp.Format("%.3f",startfreq); GetDlgItem(IDC_PPYSTARTFREQ)->SetWindowText(temp); temp.Format("%.3f",stopfreq); GetDlgItem(IDC_PPYSTOPFREQ)->SetWindowText(temp); temp.Format("%.3f",stepfreq); GetDlgItem(IDC_PPYSTEPFREQ)->SetWindowText(temp); temp.Format("%.3f",xhyfreq); GetDlgItem(IDC_XHYFREQ)->SetWindowText(temp); temp.Format("%.2f",xhyamp); GetDlgItem(IDC_XHYAMP)->SetWindowText(temp); GetDlgItem(IDC_XHYVISA)->SetWindowText(XHYvisa); GetDlgItem(IDC_PPYVISA)->SetWindowText(PPYvisa); } void CTestDlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 CString strtmp, strPath; char tmpstr[120] = {0}; strPath = GetINIPath(); if (GetFileAttributes(strPath) == -1) { return; } GetDlgItem(IDC_XHYVISA)->GetWindowTextA(strtmp); ::WritePrivateProfileString("设置","信号源VISA地址",strtmp,strPath); GetDlgItem(IDC_PPYVISA)->GetWindowTextA(strtmp); ::WritePrivateProfileString("设置","频谱仪VISA地址",strtmp,strPath); AfxMessageBox("修改完成"); } void CTestDlg::OnBnClickedButton2() { // TODO: 在此添加控件通知处理程序代码 CString strtmp, strPath; char tmpstr[120] = {0}; strPath = GetINIPath(); if (GetFileAttributes(strPath) == -1) { return; } GetDlgItem(IDC_PPYSTARTFREQ)->GetWindowTextA(strtmp); ::WritePrivateProfileString("设置","频谱仪起始频率",strtmp,strPath); GetDlgItem(IDC_PPYSTOPFREQ)->GetWindowTextA(strtmp); ::WritePrivateProfileString("设置","频谱仪终止频率",strtmp,strPath); GetDlgItem(IDC_PPYSTEPFREQ)->GetWindowTextA(strtmp); ::WritePrivateProfileString("设置","频谱仪频率步进",strtmp,strPath); GetDlgItem(IDC_XHYFREQ)->GetWindowTextA(strtmp); ::WritePrivateProfileString("设置","信号源频率",strtmp,strPath); GetDlgItem(IDC_XHYAMP)->GetWindowTextA(strtmp); ::WritePrivateProfileString("设置","信号源功率",strtmp,strPath); AfxMessageBox("修改完成"); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值