2014-10-04 74 views
0

我正在将一个简单的项目作为我的移动开发类的一部分。我的项目工作正常,但是,创建横向视图的活动后,两个活动停止触发Java代码。我从项目中移除了layout-land文件夹,但我的原始布局活动仍未触发java代码。布局UI不再触发java代码

我的怀疑是两者之间的联系中断,但eclipse并没有将其报告为错误。 setContentView()函数调用正确的xml,而tools:context调用正确的java。我错过了什么?

这里是的onCreate:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_calculator); 

     // assign objects to java variables 
     teValue1 = (EditText)findViewById(R.id.teValue1); 
     teValue2 = (EditText)findViewById(R.id.teValue2); 
     tvResult = (TextView)findViewById(R.id.tvResult); 
     btPlus = (Button)findViewById(R.id.btPlus); 
     btMinus = (Button)findViewById(R.id.btMinus); 
     btMultiply = (Button)findViewById(R.id.btMultiply); 
     btDivide = (Button)findViewById(R.id.btDivide); 
     btAbout = (Button)findViewById(R.id.btAbout); 

     // Add on click listeners 
     btPlus.setOnClickListener(new Add()); 
     btMinus.setOnClickListener(new Subtract()); 
     btMultiply.setOnClickListener(new Multiply()); 
     btDivide.setOnClickListener(new Divide()); 

    } 

一个点击听众:

private class Add implements OnClickListener { 
     @Override 
     public void onClick(View view) { 
      if (!teValue1.getText().toString().matches("") 
        && !teValue1.getText().toString().matches(".") 
        && !teValue2.getText().toString().matches("") 
        && !teValue2.getText().toString().matches(".")) { 
       double operand1 = Double.parseDouble(teValue1.getText() 
         .toString()); 
       double operand2 = Double.parseDouble(teValue2.getText() 
         .toString()); 
       Double result = operand1 + operand2; 
       tvResult.setText(result.toString()); 
      } 
     } 
    } 

且布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="cs325.matheson.calculator.CalculatorActivity" > 

    // UI items are here... 

    <requestFocus /> 

</RelativeLayout> 
+0

尝试清洁,'工程建设项目 - > clean'菜单 – 2014-10-04 03:49:02

+0

不触发java代码,什么ü通过点击侦听 – Panther 2014-10-04 03:57:28

+0

代码是什么意思? – committedandroider 2014-10-04 04:10:22

回答

0

的,如果在onclick方法条件从未返回真正。我修改了它们,现在它可以工作。令我困惑的是他们之前为什么工作,然后停止工作。