これらは互いにリンクされている 2 つのアクティビティですが、これらは機能していません。xml ファイルにメソッド名を onClick="menu" としてボタンとメソッドの両方に指定しました。
public class Welcome extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
/**Intent i = new Intent(this,Menup.class);
finish();
startActivity(i);*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.welcome, menu);
return true;
}
public void menu(View v)
{
finish();
Intent i = new Intent(this,Menup.class);
startActivity(i);
}
}
以下の次のアクティビティ名とコードに移動されます
public class Menup extends Activity {
Button route,map,ticket;
TextView bal;
String time,src,des,clas,journey,noa,noc,amount;
int itime,old=50,amt,camt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menup);
bal=(TextView)findViewById(R.id.textView1);
//getting the values
Intent i=getIntent();
time=i.getExtras().getString("time");
itime=Integer.valueOf(time);
src=i.getExtras().getString("src");
des=i.getExtras().getString("des");
clas=i.getExtras().getString("class");
journey=i.getExtras().getString("journey");
noa=i.getExtras().getString("noa");
noc=i.getExtras().getString("noc");
amount=i.getExtras().getString("amount");
camt=Integer.valueOf(amount);
route=(Button)findViewById(R.id.imageButton1);
map=(Button)findViewById(R.id.imageButton2);
ticket=(Button)findViewById(R.id.imageButton3);
route.getBackground().setAlpha(0);
map.getBackground().setAlpha(0);
ticket.getBackground().setAlpha(0);
amt=old-camt;
bal.setText("Current Balance "+amt);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menup, menu);
return true;
}
public void toroute(View v)
{
Intent r = new Intent(Menup.this,Route.class);
startActivity(r);
}
public void tomap(View v)
{
Intent m = new Intent(Menup.this,Map.class);
startActivity(m);
}
public void toticket(View v)
{
Intent d=new Intent(Menup.this,Tick.class);
d.putExtra("noa",noa);
d.putExtra("noc",noc);
d.putExtra("src",src);
d.putExtra("des",des);
d.putExtra("class", "Class I");
d.putExtra("journey", "Single");
d.putExtra("amount", amount);
d.putExtra("time", itime);
startActivity(d);
}
@Override
public void onBackPressed()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Exit");
builder.setMessage("Are you sure , you want to exit Ticketwala?");
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do nothing but close the dialog
finish();
System.exit(0);
dialog.dismiss();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
dialog.dismiss();
}
}).show();
}
}