package com.marshalchen.common.demoofui.ResideMenuDemo; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.*; import com.marshalchen.common.demoofui.R; import java.util.ArrayList; import java.util.List; /** * User: special * Date: 13-12-22 * Time: 下午3:26 * Mail: specialcyci@gmail.com */ public class CalendarFragment extends Fragment { private View parentView; private ListView listView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { parentView = inflater.inflate(R.layout.resize_menu_calendar, container, false); listView = (ListView) parentView.findViewById(R.id.listView); initView(); return parentView; } private void initView(){ ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>( getActivity(), android.R.layout.simple_list_item_1, getCalendarData()); listView.setAdapter(arrayAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Toast.makeText(getActivity(), "Clicked item!", Toast.LENGTH_LONG).show(); } }); } private ArrayList<String> getCalendarData(){ ArrayList<String> calendarList = new ArrayList<String>(); calendarList.add("New Year's Day"); calendarList.add("St. Valentine's Day"); calendarList.add("Easter Day"); calendarList.add("April Fool's Day"); calendarList.add("Mother's Day"); calendarList.add("Memorial Day"); calendarList.add("National Flag Day"); calendarList.add("Father's Day"); calendarList.add("Independence Day"); calendarList.add("Labor Day"); calendarList.add("Columbus Day"); calendarList.add("Halloween"); calendarList.add("All Soul's Day"); calendarList.add("Veterans Day"); calendarList.add("Thanksgiving Day"); calendarList.add("Election Day"); calendarList.add("Forefather's Day"); calendarList.add("Christmas Day"); return calendarList; } }