Android Open Source - Planets-App Custom Adapter






From Project

Back to project page Planets-App.

License

The source code is released under:

Apache License

If you think the Android project Planets-App 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

package com.andrewq.planets;
/*w  w  w  .  java  2  s .c  o m*/
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Andrew Quebe on 4/14/14.
 */
public class CustomAdapter extends BaseAdapter {

    Context context;
    List<RowItem> rowItem;

    CustomAdapter(Context context, List<RowItem> rowItem) {
        this.context = context;
        this.rowItem = rowItem;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.drawer_list_item, null);
            holder = new ViewHolder();
            holder.icon = (ImageView) convertView.findViewById(R.drawable.ic_launcher);
            holder.title = (TextView) convertView.findViewById(R.string.app_name);

            RowItem row_pos = rowItem.get(position);
            // setting the image resource and title
            holder.icon.setImageResource(row_pos.getIcon());
            holder.title.setText(row_pos.getTitle());
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        return convertView;

    }

    @Override
    public int getCount() {
        return rowItem.size();
    }

    @Override
    public Object getItem(int position) {
        return rowItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return rowItem.indexOf(getItem(position));
    }

    private class ViewHolder {
        ImageView icon;
        TextView title;
    }

}




Java Source Code List

com.andrewq.planets.CustomAdapter.java
com.andrewq.planets.Deimos.java
com.andrewq.planets.EclairMotionEvent.java
com.andrewq.planets.FragmentA.java
com.andrewq.planets.FragmentB.java
com.andrewq.planets.FragmentC.java
com.andrewq.planets.FragmentD.java
com.andrewq.planets.FragmentE.java
com.andrewq.planets.FragmentF.java
com.andrewq.planets.FragmentG.java
com.andrewq.planets.FragmentH.java
com.andrewq.planets.FragmentHome.java
com.andrewq.planets.FragmentI.java
com.andrewq.planets.FragmentPlanets.java
com.andrewq.planets.ImageGallery.java
com.andrewq.planets.Phobos.java
com.andrewq.planets.RandomQuotes.java
com.andrewq.planets.RowItem.java
com.andrewq.planets.SatelliteEarth.java
com.andrewq.planets.Settings.java
com.andrewq.planets.SunGLActivity.java
com.andrewq.planets.SunRenderer.java
com.andrewq.planets.TouchImageView.java
com.andrewq.planets.VenusRenderer.java
com.andrewq.planets.WrapMotionEvent.java
com.obsidian.planets.Main.java