我已经创建了一个应用程序,因为我有一个包含 TextView 和一个按钮的活动。现在这个活动在应用程序中被多次使用,所以我想要的是当我单击该活动中的后退按钮时,它应该转到上一个活动.简而言之,它应该作为设备的后退按钮。我的代码如下:
此活动用于 4 个活动,
所以我尝试如下:
Advance_help.java
package com.theappgeeks.kevingreenwealth;
import java.text.BreakIterator;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AdvanceHelp extends Activity implements OnClickListener{
Button btn;
Calculator_1Activity cal1 =new Calculator_1Activity();
Calculator2 cal2 =new Calculator2();
Calculator_3Activity cal3 =new Calculator_3Activity();
Calculator_4Activity cal4 =new Calculator_4Activity();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_advance_help);
btn=(Button)findViewById(R.id.button1);
/*btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(btn.)
Intent i1=new Intent(AdvanceHelp.this,Calculator_1Activity.class);
startActivity(i1);
}
});*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_advance_help, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.equals(cal1)){
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1= new Intent(AdvanceHelp.this,Calculator_1Activity.class);
startActivity(i1);
}
});
}
else if(v.equals(cal2)){
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1= new Intent(AdvanceHelp.this,Calculator2.class);
startActivity(i1);
}
});
}
else if(v.equals(cal3)){
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1= new Intent(AdvanceHelp.this,Calculator2.class);
startActivity(i1);
}
});
}
else if(v.equals(cal4)){
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1= new Intent(AdvanceHelp.this,Calculator2.class);
startActivity(i1);
}
});
}
else
{
Intent i = new Intent(AdvanceHelp.this,MainMenuActivity.class);
startActivity(i);
}
}
}
请尽快帮助我..提前谢谢你