使用if else语句

时间:2015-07-16 10:03:16

标签: android

我正在开发一个有三个活动的活动项目。我想使用if else条件转到2nd or 3rd activity但不知道如何在android.here中使用它我的代码

MainActivity.java

  public class MainActivity extends ActionBarActivity {
    EditText etOp;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.d("MainActivity", "-----------OnCreate--------------");
    etOp = (EditText) findViewById(R.id.etInput);

}



public void Submit(View v) {
    String OpStr = etOp.getText().toString();
    double etInput = Double.parseDouble(OpStr);
    int etOp = 11;




    if (etOp == 11) {

        Intent intent = new Intent(this, AnotherActivity.class);
        startActivity(intent);
    }
    else {

        Intent intent = new Intent(this, ThirdActivity.class);
        startActivity(intent);
    }


}

2 个答案:

答案 0 :(得分:0)

你朝着正确的方向前进:

DROP TABLE IF EXISTS rates;

CREATE TABLE rates
(season_id INT NOT NULL PRIMARY KEY
,season_type VARCHAR(12) 
,season_start DATE NOT NULL
,season_end DATE NOT NULL 
,rate INT NOT NULL
);

INSERT INTO rates VALUES
(1,'Peak','2015-08-15','2015-08-30',50),
(1,'Mid' ,'2015-09-01','2015-09-30',25);


SELECT * FROM rates;
+-----------+-------------+--------------+------------+------+
| season_id | season_type | season_start | season_end | rate |
+-----------+-------------+--------------+------------+------+
|         1 | Peak        | 2015-08-15   | 2015-08-30 |   50 |
|         2 | Mid         | 2015-09-01   | 2015-09-30 |   25 |
+-----------+-------------+--------------+------------+------+

SELECT x.*
     , DATEDIFF(season_end,'2015-08-15') 
  FROM rates x 
 WHERE '2015-08-15' >= season_start
 UNION
SELECT x.*
     , DATEDIFF('2015-09-15',season_start) 
  FROM rates x 
 WHERE '2015-09-15' <= season_end;
+-----------+-------------+--------------+------------+------+-----------------------------------+
| season_id | season_type | season_start | season_end | rate | DATEDIFF(season_end,'2015-08-15') |
+-----------+-------------+--------------+------------+------+-----------------------------------+
|         1 | Peak        | 2015-08-15   | 2015-08-30 |   50 |                                15 |
|         2 | Mid         | 2015-09-01   | 2015-09-30 |   25 |                                14 |
+-----------+-------------+--------------+------------+------+-----------------------------------+

答案 1 :(得分:0)

首先调用submit方法.................. 然后自动调用另一个活动....

像那样......

  Button btn = (Button) findViewById(R.id.btnId);
  btn.setOnClickListener(new OnClickListener() 
  {

        @Override
        public void onClick(View v) 
        {
            // TODO Auto-generated method stub
            submit();
        }
  });