ソフトウエアキーボードが出ません

22 views
Skip to first unread message

Naoyuki Kasai

unread,
Feb 24, 2012, 6:19:18 PM2/24/12
to androidi...@googlegroups.com
たろサ様
 笠井です。
 廻りに聞ける人がいないので投稿させて頂きました。
 もし、分かりましたらご教授下さい。
 画面遷移させる時はActivityを分けないとダメなんでしょうかね?
  ソースを同封します。
  よろしくお願いします。

【状況】
 ボタンのOnClickで、Layoutを遷移させた時にソフトウエアキーボードを出す事ができません。
 ボタンではなくて、無条件で推移させると出るので原因がよくわかりません。

【ソース説明】
 ①の状態だと2画面目のEditBoxをタップしてもキーボードが出ない。
 ②を有効にすると、2画面目のEditBoxをタップした際にキーボードが出る。

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(); 
}
});
    }
}

------------------ main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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>

Test.zip

たろサ

unread,
Feb 25, 2012, 11:20:46 AM2/25/12
to androidi...@googlegroups.com
 たろサです。

 テスト版を試しました。確かに、ダメですね。
 ed.setOnFocusChangeListener(this);とかして、強引に割り込みでソフトキーボードを出そうとしても、割り
込みに飛ばないですね。
 
 Activityを分けなくても、Viewを分ければいいのかなとも思うのですが、

 すいません、どなたか詳しい方、よろしくお願いします。

> --
> このメールは Google グループのグループ「Android勉強会inWAKAYAMA」の登録者に送られています。
> このディスカッションをウェブ上で閲覧するには、https://groups.google.com/d/msg/androidinwakayama/-
> /rF0f68NqqPEJ にアクセスしてください。
> このグループに投稿するには、androidi...@googlegroups.com にメールを送信してください。
> このグループから退会するには、androidinwakay...@googlegroups.com にメールを送信してくだ
> さい。
> 詳細については、http://groups.google.com/group/androidinwakayama?hl=ja からこのグループにアクセスし
> てください。

--
山本三七男 (Minao Yamamoto) ---------------- ハンドル:たろサ -----
E-Mail: taro...@gmail.com

Naoyuki Kasai

unread,
Feb 25, 2012, 11:07:54 PM2/25/12
to Android勉強会inWAKAYAMA
笠井です。

 たろサ様、実証までして頂いて恐縮です。
 ありがとうございました。

 Activityを別にしたら、キーボードが表示されました。
 とりあえずこれでしのぎたいと思います。

 結構直さないといけないけれど...。

以上
Reply all
Reply to author
Forward
0 new messages