public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnNextPage = (Button)findViewById(R.id.button1);
btnNextPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NextPage(); //← ①ここから推移するとキーボードが出ない!!
}
});
//NextPage(); ← ②ここから推移するとキーボードが出る
}
public void NextPage(){
setContentView(R.layout.nextpage);
final EditText ed = (EditText)findViewById(R.id.editText1);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(ed,0);
Button btnEnd = (Button)findViewById(R.id.button2);
btnEnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="154dp" android:text="NextPage"></Button>
</LinearLayout>
------------------ nextpage.xml
<?xml version="1.0" encoding="utf-8"?>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="fill_parent">
<requestFocus></requestFocus>
</EditText>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="End" android:id="@+id/button2"></Button>
</LinearLayout>