你好只是头痛。无法找到问题。所有按钮都正常工作,并从一个活动正确跳转到另一个活动,但“按钮关于”无法正常工作。它必须跳到“关于活动”...请检查代码问题...“关于按钮”有问题有评论,并在最后...谢谢和问候
有关于按钮的活动
package com.example.routetracker;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Select_destination extends Activity implements OnClickListener{
Button close,main,about,texila,aslam_market,royal_son,comsat;
MediaPlayer mPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_destination);
mPlayer=MediaPlayer.create(this, R.raw.selectdestination);
mPlayer.start();
texila=(Button)findViewById(R.id.btn_texila);
texila.setOnClickListener(this);
aslam_market=(Button)findViewById(R.id.btn_aslam_market);
aslam_market.setOnClickListener(this);
royal_son=(Button)findViewById(R.id.btn_royal_son);
royal_son.setOnClickListener(this);
comsat=(Button)findViewById(R.id.btn_comsat_wah);
comsat.setOnClickListener(this);
main=(Button)findViewById(R.id.btn_main);
main.setOnClickListener(this);
about=(Button)findViewById(R.id.btn_about);
about.setOnClickListener(this);
close=(Button)findViewById(R.id.btn_close);
close.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_texila:
mPlayer.stop();
Intent i=new Intent(Select_destination.this,Start_tracking.class);
i.putExtra("place", "1");
startActivity(i);
break;
case R.id.btn_aslam_market:
mPlayer.stop();
Intent j=new Intent(Select_destination.this,Start_tracking.class);
j.putExtra("place", "2");
startActivity(j);
break;
case R.id.btn_royal_son:
mPlayer.stop();
Intent k=new Intent(Select_destination.this,Start_tracking.class);
k.putExtra("place", "3");
startActivity(k);
break;
case R.id.btn_comsat_wah:
mPlayer.stop();
Intent l=new Intent(Select_destination.this,Start_tracking.class);
l.putExtra("place", "4");
startActivity(l);
break;
case R.id.btn_main:
mPlayer.stop();
Intent o=new Intent(Select_destination.this,MainActivity.class);
startActivity(o);
break;
case R.id.btn_about: // for this button i have problem
mPlayer.stop();
Intent e=new Intent(Select_destination.this,About.class);
startActivity(e);
break;
case R.id.btn_close:
mPlayer.stop();
System.exit(1);
}
}
}
关于活动代码
package com.example.routetracker;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class About extends Activity implements OnClickListener{
Button close,main;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
main=(Button)findViewById(R.id.btn_main);
main.setOnClickListener(this);
close=(Button)findViewById(R.id.btn_close);
close.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_main:
Intent o=new Intent(About.this,MainActivity.class);
startActivity(o);
break;
case R.id.btn_close:
System.exit(1);
break;
}
}
}
关于按钮的XML代码
<Button
android:id="@+id/btn_about"
android:layout_width="97dp"
android:layout_height="90dp"
android:layout_alignBaseline="@+id/btn_main"
android:layout_alignBottom="@+id/btn_main"
android:layout_toRightOf="@+id/btn_main"
android:text="About" />