在视图之间切换时出错。我在xml中的每个图像按钮上都有android:onClick="onClick"
。这是代码
selfHelp = (ImageButton)findViewById(R.id.selfhelpButton);
services = (ImageButton)findViewById(R.id.services);
messages = (ImageButton)findViewById(R.id.mailButton);
about = (ImageButton)findViewById(R.id.aboutButton);
more = (ImageButton)findViewById(R.id.moreButton);
selfHelp.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), SelfHelp.class);
startActivity(myIntent);
}
});
Services.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Services.class);
startActivity(myIntent);
}
});
messages.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Messages.class);
startActivity(myIntent);
}
});
about.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), About.class);
startActivity(myIntent);
}
});
more.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), More.class);
startActivity(myIntent);
}
});
我在另一个只有一个按钮的页面上工作,但图像按钮不起作用。任何帮助都会很棒
答案 0 :(得分:1)
你有两个选择
android:onClick="onClick"
,因为您
已经在你的按钮上设置了点击监听器覆盖了
默认 onClick()方法。删除所有 setOnclickListener()方法,并在ImageButtons中添加属性:
android:onClick="onClick"
android:clickable="true"
在您的活动使用中:
public void onClick(View v){
Intent i = null;
switch(v.getId()){
case R.id.services:
i = new Intent(this,Services.class);
startActivity(i);
break;
case R.id.mailButton:
..........
break;
}