显示错误

时间:2014-04-14 06:23:31

标签: android eclipse

我遇到了一个问题。当我在此页面(主菜单)并尝试单击计算按钮时,它将返回登录页面。但是,计算和记录页面也都打开了,可以通过单击后退按钮来访问。

Button Calculate;
Button Records;
Button Logout;

Calculate = (Button) findViewById(R.id.buttonCalculate);
Records =(Button) findViewById(R.id.buttonRecords);
Logout = (Button) findViewById(R.id.buttonLogout);


Calculate.setOnClickListener(this);
Records.setOnClickListener(this);
Logout.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.mainmenu, menu);
    return true;
}

public void onClick(View view)
{
    Intent i = new Intent(this,Calculate.class);
    startActivity(i);

    Intent f = new Intent(this,Records.class);
    startActivity(f);

    Intent g = new Intent(this,MainActivity.class);
    startActivity(g);



}

}

2 个答案:

答案 0 :(得分:1)

尝试这种方式:

public void onClick(View v)
 {

 switch(v.getId()){

  case R.id.buttonCalculate;
  Intent i = new Intent(this,Calculate.class);
  startActivity(i);
  break;

  case R.id.buttonRecords;
   Intent f = new Intent(this,Records.class);
   startActivity(f);
   break;

   case R.id.buttonLogout;
   Intent g = new Intent(this,MainActivity.class);
   startActivity(g);
   break;

  default:
  break;
 }
}

并确保您必须添加manifest.xml文件

中的所有活动

答案 1 :(得分:0)

试试这个..

public void onClick(View view)
{

    Switch(view.getId()){

    case R.id.buttonCalculate;    
         Intent i = new Intent(this,Calculate.class);
         startActivity(i);    
    break;

    case R.id.buttonRecords;
         Intent f = new Intent(this,Records.class);
         startActivity(f);
    break;

    case R.id.buttonLogout;
         Intent g = new Intent(this,MainActivity.class);
         startActivity(g);
    break;
    }
}