@Override
  protected CardHeader initCardHeader() {

    // Add Header
    CardHeader header =
        new CardHeader(getContext(), R.layout.carddemo_googlenowweather_inner_header);

    // Add a popup menu. This method set OverFlow button to visible
    header.setPopupMenu(
        R.menu.popup_item,
        new CardHeader.OnClickCardHeaderPopupMenuListener() {
          @Override
          public void onMenuItemClick(BaseCard card, MenuItem item) {

            switch (item.getItemId()) {
              case R.id.action_add:
                // Example: add an item
                WeatherObject w1 = new WeatherObject(GoogleNowWeatherCard.this);
                w1.city = "Madrid";
                w1.temperature = 24;
                w1.weatherIcon = R.drawable.ic_action_sun;
                w1.setObjectId(w1.city);
                mLinearListAdapter.add(w1);
                break;
              case R.id.action_remove:
                // Example: remove an item
                mLinearListAdapter.remove(mLinearListAdapter.getItem(0));
                break;
            }
          }
        });
    header.setTitle("Weather"); // should use R.string.
    return header;
  }
Пример #2
0
    private void init() {
      CardHeader header = new CardHeader(getContext());
      header.setButtonOverflowVisible(true);
      header.setTitle(headerTitle);
      header.setPopupMenu(
          R.menu.popupmain,
          new CardHeader.OnClickCardHeaderPopupMenuListener() {
            @Override
            public void onMenuItemClick(BaseCard card, MenuItem item) {
              Toast.makeText(getContext(), "Item " + item.getTitle(), Toast.LENGTH_SHORT).show();
            }
          });

      addCardHeader(header);

      GplayGridThumb thumbnail = new GplayGridThumb(getContext());
      if (resourceIdThumbnail > -1) thumbnail.setDrawableResource(resourceIdThumbnail);
      else thumbnail.setDrawableResource(R.drawable.ic_ic_launcher_web);
      addCardThumbnail(thumbnail);

      setOnClickListener(
          new OnCardClickListener() {
            @Override
            public void onClick(Card card, View view) {
              // Do something
            }
          });
    }