2012-02-14 27 views
0

我是一名Android程序开发的初学者......但是我给了一个任务来开发Android手机中的示波器..我在调试程序时已经有了一些程序。 我已经为使用这些代码示波器..按钮开发Android示波器

run_buton = (ToggleButton) findViewById(R.id.tbtn_runtoggle); 
    run_buton.setOnClickListener(this); 
    rb1 = (RadioButton)findViewById(R.id.rbtn_ch1); 
    rb2 = (RadioButton)findViewById(R.id.rbtn_ch2); 

public static final int rbtn_ch1 = 0; 
public static final int rbtn_ch2 = 0; 
public static final int txt_ch1pos = 0; 
public static final int txt_ch2pos = 0; 
public static final int button_connect = 0; 
public static final int WaveformArea = 0; 
public static int btn_position_down; 
public static int tbtn_runtoggle; 
public static int btn_position_up; 
btn_pos_up = (Button) findViewById(R.id.btn_position_up); 
btn_pos_down = (Button) findViewById(R.id.btn_position_down); 
btn_pos_up.setOnClickListener(this); 
btn_pos_down.setOnClickListener(this); 

和我R.id.之后设置的所有东西是一个整数/场.. 这在R档如下图所示

然而Eclispe的告诉我,我有计划在最后三场......这是“btn_posiion_down”,“tbtn_runtoggle”和“btn_postion_up” .. 它显示错误,说“情况的表述应该是常数表达式” ......我不明白这是什么意思?该脚本的第一句话得到错误...

case R.id.btn_position_up : 
     if(rb1.isChecked() && (ch1_pos<38)){ 
      ch1_pos += 1; ch1pos_label.setPadding(0, toScreenPos(ch1_pos), 0, 0); 
      sendMessage(new String(new byte[] {ADJ_POSITION, CHANNEL1, ch1_pos})); 
     } 
     else if(rb2.isChecked() && (ch2_pos<38)){ 
      ch2_pos += 1; ch2pos_label.setPadding(0, toScreenPos(ch2_pos), 0, 0); 
      sendMessage(new String(new byte[] {ADJ_POSITION, CHANNEL2, ch2_pos})); 
     } 
     break; 

五月人好心地告诉我会发生什么?

+0

嗨,我正在开发一个用示波器录音的应用程序。我不知道如何获得示波器。请提供一些示例代码。谢谢。 – 2012-06-06 15:46:13

回答

1

听起来好像您正在使用定义这些ID的库项目。如果是这样的话,你不能在这些id中使用switch语句,因为它们不是静态的final。

尝试使用if/else语句而不是开关。日蚀快速修复工具将建议您为您解决问题。

+0

我必须纠正上面的所有静态最终?或只有那些有错误?我使用快速修复..它建议我把它变成整数/字段...- - 并仍然得到错误 – 2012-02-14 16:50:28

+0

,而不是使用“case R.id.btn_position_up”使用if(id == R.id. btn_position_up) – 2012-02-15 19:17:52

+0

嗨,我正在开发一款应用程序,用示波器进行录音。我不知道如何获得示波器。请提供一些示例代码。谢谢。 – 2012-06-06 15:46:38