Ejemplo n.º 1
0
 public void search(String query) {
   Log.d(TAG, "Search Sumbitted");
   Bundle bundle = new Bundle();
   bundle.putString("query", query);
   SearchListFragment list =
       (SearchListFragment)
           getSupportFragmentManager().findFragmentById(R.id.search_list_fragment);
   if (list == null) {
     list =
         (SearchListFragment)
             getSupportFragmentManager().findFragmentById(R.id.fragment_container);
   }
   list.search(bundle);
 }
Ejemplo n.º 2
0
  /* (non-Javadoc)
   * @see android.support.v7.app.ActionBarActivity#onCreate(android.os.Bundle)
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    if (getResources().getBoolean(R.bool.portrait_only)) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    if (findViewById(R.id.fragment_container) != null) {

      if (savedInstanceState != null) {
        return;
      }

      SearchListFragment searchListFragment = new SearchListFragment();
      searchListFragment.setArguments(getIntent().getExtras());
      getSupportFragmentManager()
          .beginTransaction()
          .add(R.id.fragment_container, searchListFragment)
          .commit();
    }
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    EditText search = (EditText) findViewById(R.id.searchQuery);

    search.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            search(cs.toString());
          }

          @Override
          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub

          }

          @Override
          public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
          }
        });
  }