Android Open Source - NavigationDrawer Planet Adapter






From Project

Back to project page NavigationDrawer.

License

The source code is released under:

Apache License

If you think the Android project NavigationDrawer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 The Android Open Source Project
 */*  w ww .jav a 2 s .com*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.navigationdrawer;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Adapter for the planet data used in our drawer menu,
 */
public class PlanetAdapter extends RecyclerView.Adapter<PlanetAdapter.ViewHolder> {
  private String[] mDataset;
  private OnItemClickListener mListener;

  /**
   * Interface for receiving click events from cells.
   */
  public interface OnItemClickListener {
    public void onClick(View view, int position);
  }

  /**
   * Custom viewholder for our planet views.
   */
  public static class ViewHolder extends RecyclerView.ViewHolder {
    public final TextView mTextView;

    public ViewHolder(TextView v) {
      super(v);
      mTextView = v;
    }
  }

  public PlanetAdapter(String[] myDataset, OnItemClickListener listener) {
    mDataset = myDataset;
    mListener = listener;
  }

  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater vi = LayoutInflater.from(parent.getContext());
    View v = vi.inflate(R.layout.drawer_list_item, parent, false);
    TextView tv = (TextView) v.findViewById(android.R.id.text1);
    return new ViewHolder(tv);
  }

  @Override
  public void onBindViewHolder(ViewHolder holder, final int position) {
    holder.mTextView.setText(mDataset[position]);
    holder.mTextView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        mListener.onClick(view, position);
      }
    });
  }

  @Override
  public int getItemCount() {
    return mDataset.length;
  }
}




Java Source Code List

com.example.android.common.logger.LogFragment.java
com.example.android.common.logger.LogNode.java
com.example.android.common.logger.LogView.java
com.example.android.common.logger.LogWrapper.java
com.example.android.common.logger.Log.java
com.example.android.common.logger.MessageOnlyLogFilter.java
com.example.android.navigationdrawer.MainActivity.java
com.example.android.navigationdrawer.NavigationDrawerActivity.java
com.example.android.navigationdrawer.PlanetAdapter.java
com.example.android.navigationdrawer.PlanetBitmap.java