Android Open Source - HastingsMobileAndroid Custom Events Adapter






From Project

Back to project page HastingsMobileAndroid.

License

The source code is released under:

Apache License

If you think the Android project HastingsMobileAndroid 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 edu.hastings.hastingscollege.adapter;
/*from   w w w .j a  va  2s  . c  om*/
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import edu.hastings.hastingscollege.R;
import edu.hastings.hastingscollege.model.EventModel;

public class CustomEventsAdapter extends BaseAdapter {
    private static final String TAG = CustomEventsAdapter.class.getSimpleName();

    ArrayList<EventModel> listArray;

    private static final String TAG_TITLE = "event_title";
    private static final String TAG_LOCATION = "event_location";
    private static final String TAG_TIME = "event_time";

    public CustomEventsAdapter(ArrayList<EventModel> eventsArrayList) {
        this.listArray = eventsArrayList;
    }

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

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

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

    @Override
    public View getView(int position, View convertView, final ViewGroup parent){
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.list_item_event, parent, false);
        }

        final EventModel eventModel = listArray.get(position);

        TextView eventName = (TextView) convertView.findViewById(R.id.event_name);
        eventName.setText(eventModel.eventName);

        TextView eventWeek = (TextView) convertView.findViewById(R.id.event_week);
        eventWeek.setText(eventModel.eventWeek);

        final Button eventInfoBtn = (Button) convertView.findViewById(R.id.more_info_btn);
        eventInfoBtn.setOnClickListener(new View.OnClickListener() {
            final LayoutInflater layoutInflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            @Override
            public void onClick(View v) {
                View eventDialogView = layoutInflater.inflate(R.layout.event_dialog, null);
                LinearLayout eventDialogLayout = (LinearLayout) eventDialogView.findViewById(R.id.event_info_dialog);
                for(int i = 0; i < eventModel.eventsOfDay.size(); i++) {
                    LinearLayout eventDaySection = (LinearLayout) layoutInflater.inflate(R.layout.event_information_template, eventDialogLayout, false);
                    TextView eventDayHeaderText = (TextView) eventDaySection.findViewById(R.id.day_label);
                    eventDayHeaderText.setText(eventModel.eventDays[i]);
                    ListView eventInfoList = (ListView) eventDaySection.findViewById(R.id.event_info_list);
                    eventInfoList.addHeaderView(new View(parent.getContext()));
                    eventInfoList.addFooterView(new View(parent.getContext()));
                    String[] from = {TAG_TITLE, TAG_LOCATION, TAG_TIME};
                    int[] to = {R.id.event_title, R.id.event_location, R.id.event_time};
                    SimpleAdapter adapter = new SimpleAdapter(parent.getContext(), eventModel.eventsOfDay.get(i), R.layout.list_item_event_info, from, to);
                    eventInfoList.setAdapter(adapter);
                    HelperExpandListView.getListViewSize(eventInfoList);
                    eventInfoList.setClickable(false);
                    eventDialogLayout.addView(eventDaySection);
                }

                final Dialog dialog = new Dialog(parent.getContext());
                dialog.setContentView(eventDialogView);
                dialog.setTitle(eventModel.eventName);
                dialog.setCancelable(true);
                dialog.setCanceledOnTouchOutside(true);
                dialog.show();
            }
        });
        return convertView;
    }
}




Java Source Code List

edu.hastings.hastingscollege.BuildConfig.java
edu.hastings.hastingscollege.BuildConfig.java
edu.hastings.hastingscollege.MainActivity.java
edu.hastings.hastingscollege.SettingsActivity.java
edu.hastings.hastingscollege.SodexoXmlParser.java
edu.hastings.hastingscollege.SplashActivity.java
edu.hastings.hastingscollege.adapter.ContactsDataModel.java
edu.hastings.hastingscollege.adapter.CustomEContactsAdapter.java
edu.hastings.hastingscollege.adapter.CustomEventsAdapter.java
edu.hastings.hastingscollege.adapter.CustomSodexoWeekMenuAdapter.java
edu.hastings.hastingscollege.adapter.HelperExpandListView.java
edu.hastings.hastingscollege.adapter.TabsPagerAdapter.java
edu.hastings.hastingscollege.connection.Connection.java
edu.hastings.hastingscollege.connection.HttpAuthenticationDialog.java
edu.hastings.hastingscollege.connection.ServiceHandler.java
edu.hastings.hastingscollege.googleanalytics.MyApplication.java
edu.hastings.hastingscollege.map_db.LocationsDB.java
edu.hastings.hastingscollege.model.Data.java
edu.hastings.hastingscollege.model.EventModel.java
edu.hastings.hastingscollege.model.MapLocation.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentAbout.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentAthletics.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentBroncoboard.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentCampusEvents.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentDiningHall.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentEmergencyContacts.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentHome.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentMap.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentTwitter.java
edu.hastings.hastingscollege.tabfragments.BreakfastFragment.java
edu.hastings.hastingscollege.tabfragments.DinnerFragment.java
edu.hastings.hastingscollege.tabfragments.LunchFragment.java
edu.hastings.hastingscollege.tabfragments.SingleMenuItemNutritionFactsActivity.java
edu.hastings.hastingscollege.tabfragments.SodexoMenu.java