4

私のアプリケーションでは、viewPager を使用して素敵なスワイプ ビューを提供しています。キーボードを 2 つのページで非表示にしたいのですが、テキスト ボックスがある 1 つのページで常に表示します。

キーボードを表示するためにさまざまな方法を試しましたが、うまくいきません。間違った場所でディスプレイ キーボード コードを呼び出しているに違いないと思います。

 @Override
public Object instantiateItem( View collection, int position )
{
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = null;
    if(position==0){
        layout=inflater.inflate(R.layout.other, null);
        //new PC().create(layout, context);
        ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(collection.getWindowToken(), 0);
    }else if(position==1){
        layout=inflater.inflate(R.layout.main, null);
        new BlurayRemote().create(layout,context);
        ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(collection.getWindowToken(), 0);
    }else if(position==2){
        layout=inflater.inflate(R.layout.text, null);
        new TextInput().create(layout,context);
        ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(collection.getWindowToken(), 0);
    }

    ((ViewPager) collection).addView(layout);

    return layout;      
}

それは私を怒らせているので、どんな助けも素晴らしいでしょう!

4

2 に答える 2

3

これを行うにはもっと良い方法があると確信していますが、同じ問題を抱えていたので、親Viewをフォーカス可能に設定することで回避しました。そうすれば、ページ間をスワイプしたときに、ソフト キーボードがポップアップする原因が何であれ、フォーカスを受け取らなくなります。

<!-- Dummy item to prevent your View from receiving focus -->
<LinearLayout
    ...
    android:focusable="true" 
    android:focusableInTouchMode="true" />

    <!-- The view(s) that are causing the keyboard to pop up each time you swipe -->
    <EditText ... />

</LinearLayout>
于 2012-02-17T16:58:43.343 に答える
1

間違ったコンテキストを使用すると、通常は問題が発生することがわかりました。これを試して。

@Override
public Object instantiateItem( View collection, int position )
{
    LayoutInflater inflator = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = null;
    if(position==0){
        layout=inflater.inflate(R.layout.other, null);
        //new PC().create(layout, context);
        ((InputMethodManager)collection.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(collection.getWindowToken(), 0);
    }else if(position==1){
        layout=inflater.inflate(R.layout.main, null);
        new BlurayRemote().create(layout, collection.getContext());
        ((InputMethodManager)collection.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(collection.getWindowToken(), 0);
    }else if(position==2){
        layout=inflater.inflate(R.layout.text, null);
        new TextInput().create(layout,collection.getContext());
        ((InputMethodManager)collection.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(collection.getWindowToken(), 0);
    }

    ((ViewPager) collection).addView(layout);

    return layout;      
}
于 2011-10-13T15:51:38.660 に答える