public class MainActivity extends ActionBarActivity {
private ImageButton speech01;
private ImageButton speech02;
private ImageButton sheet01;
private ImageButton sheet02;
private ImageButton information01;
private ImageButton information02;
private ImageButton class01;
private ImageButton class02;
private Button search;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
speech01 = (ImageButton)findViewById(R.id.speech01);
speech02 = (ImageButton)findViewById(R.id.speech02);
speech01 = (ImageButton)findViewById(R.id.speech01);
speech02 = (ImageButton)findViewById(R.id.speech02);
information01 = (ImageButton)findViewById(R.id.information01);
information02 = (ImageButton)findViewById(R.id.information02);
class01 = (ImageButton)findViewById(R.id.class01);
class02 = (ImageButton)findViewById(R.id.class02);
speech01.setOnClickListener(click);
speech02.setOnClickListener(click);
speech01.setOnClickListener(click);
speech02.setOnClickListener(click);
information01.setOnClickListener(click);
information02.setOnClickListener(click);
class01.setOnClickListener(click);
class02.setOnClickListener(click);
}
private View.OnClickListener click = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch ((v.getId())){
case R.id.speech01:
case R.id.speech02:
case R.id.sheet01:
case R.id.sheet02:
case R.id.information01:
case R.id.information02:
case R.id.class01:
case R.id.class02:
Intent intent = new Intent();
intent.setClass(MainActivity.this, PlayActivity.class);
startActivity(intent);
break;
default:
break;
}
}
};
------解决思路----------------------
无法运行,logcat有什么提示
------解决思路----------------------
应该是:android只会到Activity中去找onClick方法,而不会到Fragment中去找。是不是把代码拷贝到Fragment中去了。
------解决思路----------------------
HomePageActivity这个文件中的错误,而不是MainActivity中的错误。