@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.view_pager_multi_fragment_demo);

    viewPager = (ViewPager) findViewById(R.id.view_pager);
    indexText = (TextView) findViewById(R.id.view_pager_index);
    viewPagerContainer = (RelativeLayout) findViewById(R.id.pager_layout);
    viewPager.setAdapter(new MyPagerAdapter());
    // to cache all page, or we will see the right item delayed
    viewPager.setOffscreenPageLimit(TOTAL_COUNT);
    viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin));
    viewPager.setOnPageChangeListener(new MyOnPageChangeListener());

    viewPagerContainer.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // dispatch the events to the ViewPager, to solve the problem that we can swipe only the
            // middle view.
            return viewPager.dispatchTouchEvent(event);
          }
        });
    indexText.setText(new StringBuilder().append("1/").append(TOTAL_COUNT));
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.drop_down_listview_demo);

    listView = (DropDownListView) findViewById(R.id.list_view);
    // set drop down listener
    listView.setOnDropDownListener(
        new OnDropDownListener() {

          @Override
          public void onDropDown() {
            new GetDataTask(true).execute();
          }
        });

    // set on bottom listener
    listView.setOnBottomListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            new GetDataTask(false).execute();
          }
        });

    listItems = new LinkedList<String>();
    listItems.addAll(Arrays.asList(mStrings));
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
    listView.setAdapter(adapter);
  }
Ejemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.search_view_demo);

    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    handler = new MyHandler();
    searchInfo = (TextView) findViewById(R.id.searchInfo);

    // set title style
    ActionBar bar = getActionBar();
    bar.setDisplayOptions(
        ActionBar.DISPLAY_SHOW_TITLE
            | ActionBar.DISPLAY_HOME_AS_UP
            | ActionBar.DISPLAY_SHOW_CUSTOM);
    setTitle(" ");
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View customActionBarView = inflater.inflate(R.layout.search_view_demo_title, null);

    searchView = (SearchView) customActionBarView.findViewById(R.id.search_view);
    searchView.setVisibility(View.VISIBLE);
    searchView.setIconifiedByDefault(true);
    searchView.setIconified(false);
    if (Build.VERSION.SDK_INT >= 14) {
      // when edittest is empty, don't show cancal button
      searchView.onActionViewExpanded();
    }
    searchView.setOnCloseListener(
        new OnCloseListener() {

          @Override
          public boolean onClose() {
            // to avoid click x button and the edittext hidden
            return true;
          }
        });
    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {

          public boolean onQueryTextSubmit(String query) {
            searchInfo.setText("search submit result");
            hideSoftInput();
            return true;
          }

          public boolean onQueryTextChange(String newText) {
            if (newText != null && newText.length() > 0) {
              currentSearchTip = newText;
              showSearchTip(newText);
            }
            return true;
          }
        });
    Display display = getWindowManager().getDefaultDisplay();
    LayoutParams params =
        new LayoutParams(
            display.getWidth()
                - getResources().getDimensionPixelSize(R.dimen.search_view_margin_left),
            LayoutParams.WRAP_CONTENT,
            Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    bar.setCustomView(customActionBarView, params);

    // show keyboard
    getWindow()
        .setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
  }
 @Override
 protected void onStop() {
   super.onStop();
   EasyTracker.getInstance(this).activityStop(this);
 }