Android Open Source - AndroidForiOS Trip Array Adapter






From Project

Back to project page AndroidForiOS.

License

The source code is released under:

MIT License

If you think the Android project AndroidForiOS 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.example.androidforios.app.adapters;
//from  w  w  w.  j  a  va  2s .  c  om
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.example.androidforios.app.data.model.Trip;
import com.example.androidforios.app.R;

import java.text.DateFormat;

/**
 * An {@link android.widget.ArrayAdapter} that adapts {@link com.example.androidforios.app.data.model.Trip}
 * model objects for {@code view_three_item_list_view} Views.
 */
public class TripArrayAdapter extends ArrayAdapter<Trip> {

    int LAYOUT_RESOURCE_ID = R.layout.view_three_item_list_view;

    public TripArrayAdapter(Context context) {
        super(context, R.layout.view_three_item_list_view);
    }

    public TripArrayAdapter(Context context, Trip[] objects) {
        super(context, R.layout.view_three_item_list_view, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        Trip trip = this.getItem(position);
        View inflatedView = convertView;
        if(convertView==null)
        {
            LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            inflatedView = inflater.inflate(LAYOUT_RESOURCE_ID, parent, false);
        }

        TextView destinationTextView = (TextView)inflatedView.findViewById(R.id.view_three_item_list_view_left_text_view);
        TextView timeStampTextView = (TextView)inflatedView.findViewById(R.id.view_three_item_list_view_middle_text_view);
        TextView trainNameTextView = (TextView)inflatedView.findViewById(R.id.view_three_item_list_view_right_text_view);

        destinationTextView.setText(trip.destination);
        if (trip.positionTimeStamp != null) {
            timeStampTextView.setText(DateFormat.getDateTimeInstance().format(trip.positionTimeStamp));
            timeStampTextView.setVisibility(View.VISIBLE);
        } else {
            timeStampTextView.setVisibility(View.GONE);
        }
        trainNameTextView.setText(trip.trainName);

        return inflatedView;
    }
}




Java Source Code List

com.example.androidforios.app.activities.MainActivity.java
com.example.androidforios.app.activities.TripDetailActivity.java
com.example.androidforios.app.activities.TripListActivity.java
com.example.androidforios.app.adapters.LineTypeArrayAdapter.java
com.example.androidforios.app.adapters.PredictionArrayAdapter.java
com.example.androidforios.app.adapters.TripArrayAdapter.java
com.example.androidforios.app.data.managers.DataManager.java
com.example.androidforios.app.data.model.Prediction.java
com.example.androidforios.app.data.model.TripList.java
com.example.androidforios.app.data.model.Trip.java
com.example.androidforios.app.fragments.SubwayListFragment.java
com.example.androidforios.app.fragments.TripDetailFragment.java
com.example.androidforios.app.fragments.TripListFragment.java
com.example.androidforios.app.views.TripDetailsView.java