Android Open Source - LearnByHeart Items Adapter






From Project

Back to project page LearnByHeart.

License

The source code is released under:

Apache License

If you think the Android project LearnByHeart 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.mps.learn.pb.ui.factivities;
/*from www  .j  a v  a  2s .  co m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.lang.ref.WeakReference;
import java.util.List;

/**
 * Simple {@link BaseAdapter} implementation to use with any {@link List}.<br/>
 * {@link #getView(int, android.view.View, android.view.ViewGroup) getView} method is divided into
 * {@link #createView(Object, int, android.view.ViewGroup, android.view.LayoutInflater) createView} and
 * {@link #bindView(Object, int, android.view.View) bindView} methods.
 */
public abstract class ItemsAdapter<T> extends BaseAdapter {

    private List<T> mItemsList;
    private final WeakReference<Context> contextRef;
    private final LayoutInflater layoutInflater;

    public ItemsAdapter(Context context) {
        contextRef = new WeakReference<Context>(context);
        layoutInflater = LayoutInflater.from(context);
    }

    /**
     * Sets list to this adapter and calls {@link #notifyDataSetChanged()} to update underlying {@link android.widget.ListView}.<br/>
     * You can pass {@code null} to clear the adapter
     */
    public void setItemsList(List<T> list) {
        mItemsList = list;
        notifyDataSetChanged();
    }

    public List<T> getItemsList() {
        return mItemsList;
    }

    protected Context getContext() {
        return contextRef.get();
    }

    protected LayoutInflater getLayoutInflater() {
        return layoutInflater;
    }

    @Override
    public int getCount() {
        return mItemsList == null ? 0 : mItemsList.size();
    }

    @Override
    public T getItem(int position) {
        if (mItemsList == null || position < 0 || position >= mItemsList.size()) return null;
        return mItemsList.get(position);
    }

    /**
     * Default implementation of this adapter uses pos as id. So we can find item by it's id with no problems.
     */
    public T getItem(long id) {
        return getItem((int) id);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup parent) {
        T item = mItemsList.get(pos);
        if (convertView == null) convertView = createView(item, pos, parent, layoutInflater);
        bindView(item, pos, convertView);
        return convertView;
    }

    protected abstract View createView(T item, int pos, ViewGroup parent, LayoutInflater inflater);

    protected abstract void bindView(T item, int pos, View convertView);

}




Java Source Code List

com.mps.learn.pb.App.java
com.mps.learn.pb.PhraseManager.java
com.mps.learn.pb.adapter.AllPhraseAdapter.java
com.mps.learn.pb.alarm.ReminderReceiver.java
com.mps.learn.pb.alarm.ReminderUtil.java
com.mps.learn.pb.db.DataSourcePhrase.java
com.mps.learn.pb.db.DatabaseHelper.java
com.mps.learn.pb.db.PhraseReaderContract.java
com.mps.learn.pb.gcm.GcmBroadcastReceiver.java
com.mps.learn.pb.gcm.GcmIntentService.java
com.mps.learn.pb.http.DataUpdaterCallback.java
com.mps.learn.pb.http.DataUpdaterTask.java
com.mps.learn.pb.http.HttpConstant.java
com.mps.learn.pb.http.PhraseParser.java
com.mps.learn.pb.model.PhraseBook.java
com.mps.learn.pb.model.PhraseModel.java
com.mps.learn.pb.ui.activities.AddPhraseActivity.java
com.mps.learn.pb.ui.activities.MainActivity.java
com.mps.learn.pb.ui.activities.PhraseViewActivity.java
com.mps.learn.pb.ui.activities.SettingActivity.java
com.mps.learn.pb.ui.factivities.BaseActivity.java
com.mps.learn.pb.ui.factivities.FActivity.java
com.mps.learn.pb.ui.factivities.FoldableListActivity.java
com.mps.learn.pb.ui.factivities.ItemsAdapter.java
com.mps.learn.pb.ui.factivities.PaintingsAdapter.java
com.mps.learn.pb.ui.factivities.SpannableBuilder.java
com.mps.learn.pb.ui.factivities.UnfoldableDetailsActivity.java
com.mps.learn.pb.ui.views.FoldableItemLayout.java
com.mps.learn.pb.ui.views.FoldableListLayout.java
com.mps.learn.pb.ui.views.UnfoldableView.java
com.mps.learn.pb.ui.views.shading.FoldShading.java
com.mps.learn.pb.ui.views.shading.GlanceFoldShading.java
com.mps.learn.pb.ui.views.shading.SimpleFoldShading.java
com.mps.learn.pb.util.CommonConstants.java
com.mps.learn.pb.util.Debugger.java