隐藏视图和显示软键盘

时间:2014-08-27 16:59:45

标签: android view android-tabhost

我有一个View(Tabhost),我想在单击按钮时显示它,当我显示Tabhost时我隐藏了软键盘,如果我选择了相同的按钮,我想显示软键盘并隐藏Tabhost,我点击的鳕鱼是吼叫,但它没有按照我的意愿行事..可以任何身体帮助!?

public void show_smily(View view) { // event habdler
    EditText composer = (EditText) findViewById(R.id.message_composer);
    InputMethodManager imm = (InputMethodManager)getSystemService(
            Context.INPUT_METHOD_SERVICE);

    TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
    if(!tabHost.isShown()) {
        imm.hideSoftInputFromWindow(composer.getWindowToken(),0);
        tabHost.setVisibility(View.VISIBLE);
    }
    if(tabHost.isShown()) {
        tabHost.setVisibility(View.GONE);
        imm.showSoftInput(composer,0);

    }
}

1 个答案:

答案 0 :(得分:0)

好的,我忘了在第二个if之前放置else,所以,第一个条件为true,然后第二个条件为true,应用程序执行了两个块......

public void show_smily(View view) { // event habdler
EditText composer = (EditText) findViewById(R.id.message_composer);
InputMethodManager imm = (InputMethodManager)getSystemService(
        Context.INPUT_METHOD_SERVICE);

TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
if(!tabHost.isShown()) {
    imm.hideSoftInputFromWindow(composer.getWindowToken(),0);
    tabHost.setVisibility(View.VISIBLE);
}
else if(tabHost.isShown()) { // here was the problem
    tabHost.setVisibility(View.GONE);
    imm.showSoftInput(composer,0);

}

}

相关问题