I have a chat function built into my app that I am having problems with. Here is the XML:
<LinearLayout android:id="@+id/chat_window" android:orientation="vertical">
    <ListView
        android:id="@+id/received_chats"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll">
    </ListView>
    <LinearLayout android:id="@+id/control_window" android orientation="horizontal">
        <EditText android:id="@+id/chat_entry_window" />
        <Button android:id="@+id/send_chat_button" android:text="Send" />
    </LinearLayout>
</LinearLayout>
On the back end, I have an onClickListener control that fires when the button is clicked:
public class Chat extends Fragment {
    private View rootView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        rootView = inflater.inflate(R.layout.chat, container, false);
        return rootView;
    }
    @Override
    public void onViewCreated(View rootView, Bundle, savedInstanceState){
        super.onViewCreated(rootView, savedInstanceState);
        displayChats();
    }
    @Override
    public void onResume(){
        super.onResume();
        displayChats();
    }
    @Override
    public View getView(){
        Button sendChatButton = (Button) rootView.findViewById(R.id.send_chat_button);
        sendChatButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                // get EditText contents and send the chat ...
            }
        });
    }
    public void dispalyChats(){
        final ArrayAdapter adapter = new CustomArrayAdapter(getActivity, R.layout.line_of_chat_text, MainActivity.chatList);
        final ListView list = (ListView) rootView.findViewById(R.id.received_chats);
        list.smoothScrollToPosition(list.getCount() - 1);
    }
}
My problem is that when I click the "Send" button, the soft keyboard doesn't disappear and the text I entered into the EditText window does not get cleared.
I have tried this method to get the soft keyboard to disappear, but it doesn't seem to work. However, I may be trying it in the wrong place.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
What do I need to do in order to make these two things happen?
 
     
     
    