我用onConfigurationChanged
方法知道方向何时改变。但是,当我调用其他布局时,按钮不起作用。
这是我的代码:
介绍页.java
package com.example.mysqltest;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class IntroPage extends Activity implements OnClickListener {
private Button btnlogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.intropage);
btnlogin = (Button)findViewById(R.id.btnlogin);
btnlogin.setOnClickListener(this);
}
// Check screen orientation or screen rotate event here
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.intropage);
// Checks the orientation of the screen for landscape and portrait
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.intropage_landscape);
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(IntroPage.this, Login.class);
startActivity(i);
}
}
我写android:configChanges="orientation|screenSize"
在我的清单 xml 中。请有人帮助我......我可以用按钮不工作做什么?