Android Open Source - ExpertAndroid Word Meaning List Adapter

From Project

Back to project page ExpertAndroid.


The source code is released under:

MIT License

If you think the Android project ExpertAndroid 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.androidbook.parse;
//  w w w .  j a  va2s  .c  o  m
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.parse.ParseUser;

//ArrayAdapter holds the data/rows in a list or array
//it passes this row object to getView with a position
public class WordMeaningListAdapter 
extends ArrayAdapter<WordMeaning>
implements View.OnClickListener

  private static String tag = "WordMeaningListAdapter";
  //String[] wordArray;
  Context ctx = null;
  LayoutInflater lif = null;
  IReportBack reportBack = null;
  public WordMeaningListAdapter(Context context, 
      List<WordMeaning> wordMeaningList,
      IReportBack inReportBack)
        ctx = context;
        lif = LayoutInflater.from(ctx);
        reportBack = inReportBack;
  //This class saves references to the buttons that are displayed
  //for each row. if there are 10 rows then there are 10 buttons
  //and 10 instances of view holder
  static class ViewHolder
    public ViewHolder(View rowView, View.OnClickListener ocl)
      textView =
      contextView =
    //Holds the meaning line
    public TextView textView;
    //Model Object representing word meaning
    public WordMeaning wordMeaningAtThisRow;
    //should be user/date who created this meaning
    public TextView contextView;

  //For a given position return a view
  public View getView(int position, View convertView, ViewGroup parent) 
    ViewHolder vh;
    View thisView;
    if (convertView == null)
      //create the view
      View rowView =
      vh = new ViewHolder(rowView,this);
      thisView = rowView;
      //populate the view
      vh = (ViewHolder)convertView.getTag();
      thisView = convertView;
    //got a view holder
    //and a view.
    WordMeaning curwordMeaning = this.getItem(position);
    //Notice how we are placing the tags
    //in the respective buttons
    vh.wordMeaningAtThisRow = curwordMeaning;
    return thisView;
  public void onClick(View v) 
  private String getContextFromWordMeaning(WordMeaning m)
    //who created it and when
    ParseUser pu = m.getCreatedBy();
    Date d = m.getCreatedAt();
    DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
    String datestring =  df.format(d);
    return pu.getUsername() + "/" + datestring;

Java Source Code List