所以我的申请遇到了一些问题,bt3带我到bt2位置,当我不想要它时,有人可以解释一下原因吗?
public class MainActivity extends Activity {
Button bt, bt2, bt3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.button1);
bt2 = (Button) findViewById(R.id.button2);
bt3 = (Button) findViewById(R.id.button3);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
integrator.initiateScan();
}
});
bt2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(MainActivity.this, location1.class);
startActivity(intent);
}
});
bt3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(MainActivity.this, location2.class);
startActivity(intent);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
//super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
} else if (resultCode == RESULT_CANCELED) {
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
澄清每个按钮的作用:
button1
用来开始扫描,
button2
用来带我去location1,
button3
用来带我到location2。
答案 0 :(得分:0)
您可以尝试为XML中的每个按钮实现onClick
方法,看看是否会发生任何变化。