Ejemplo n.º 1
0
  private void openFragment(BaseFragment baseFragment) {
    if (baseFragment != null) {
      FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

      fragmentTransaction.replace(R.id.fragment_main, baseFragment);
      // fragmentTransaction.addToBackStack(null);
      fragmentTransaction.commit();
      if (baseFragment.getTitleResourceId() > 0) mCurrentTitle = baseFragment.getTitleResourceId();
    }
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    lv = (ListView) getView().findViewById(R.id.listView1);

    adapter =
        new MessageArrayAdapter(
            getActivity().getApplicationContext(), R.layout.listitem_discuss, msgs);

    lv.setAdapter(adapter);

    editText1 = (EditText) getView().findViewById(R.id.editText1);
    editText1.setOnKeyListener(
        new OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
              // Perform action on key press
              Message msg =
                  ((MainActivity) ConversationFragment.this.getActivity())
                      .sendMessageToConversation(conversationName, editText1.getText().toString());
              if (msg != null) {
                adapter.add(new OneMessage(false, editText1.getText().toString()));
                editText1.setText("");
                return true;
              }
            }
            return false;
          }
        });
  }