Android Open Source - grtransit List Array Adapter

From Project

Back to project page grtransit.


The source code is released under:

GNU General Public License

If you think the Android project grtransit 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 2011 Giles Malet./* w w w. j av a  2  s  .  co  m*/
 * This file is part of GRTransit.
 * GRTransit is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * GRTransit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with GRTransit.  If not, see <>.

 * An adapter that is used when drawing the main window list of details.

import android.text.Html;
import android.text.util.Linkify;
import android.text.util.Linkify.TransformFilter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ListArrayAdapter extends ArrayAdapter/* <ArrayList<String[]>> */{
  // private static final String TAG = "ListArrayAdapter";

  private final ArrayList<String[]> mDetails;
  private final LayoutInflater mInflater;
  private final int mLayout;

  // For Twitter linkify
  final Pattern mUserPattern = Pattern.compile("@([A-Za-z0-9_-]+)");
  final Pattern mHashPattern = Pattern.compile("#([A-Za-z0-9_-]+)");
  final String mUserScheme = "";
  final String mHashScheme = "";

  public ListArrayAdapter(ListActivity context, int layout, ArrayList<String[]> details) {
    super(context, layout, details);
    // Log.v(TAG, "TimesArrayAdapter()");

    mDetails = details;
    mInflater = LayoutInflater.from(context);
    mLayout = layout;

  static class ViewHolder {
    TextView stoptime;
    TextView desc;

  public View getView(int position, View view, ViewGroup parent) {

    ViewHolder holder;

    // Reuse the convertView if we already have one.... Android will create
    // only enough to fill the screen.
    if (view == null) {
      view = mInflater.inflate(mLayout, parent, false);

      // Save the view when we look them up.
      holder = new ViewHolder();
      holder.stoptime = (TextView) view.findViewById(;
      holder.desc = (TextView) view.findViewById(;


    } else {
      // Log.d(TAG, "reusing view " + view);
      holder = (ViewHolder) view.getTag();


    // Linkify twitter text.
    if (mLayout == R.layout.tweetlayout) {

      // Might be things like &amp; in there....

      // Transform filter returns just the text captured by the first regular expression group.
      final TransformFilter TFilter = new TransformFilter() {
        public final String transformUrl(final Matcher match, String url) {

      Linkify.addLinks(holder.desc, Linkify.ALL); // the defaults
      Linkify.addLinks(holder.desc, mUserPattern, mUserScheme, null, TFilter);
      Linkify.addLinks(holder.desc, mHashPattern, mHashScheme, null, TFilter);
    } else {

    return view;

Java Source Code List