Android Open Source - UTHPortal-Android-Gradle Expandable List Adapter






From Project

Back to project page UTHPortal-Android-Gradle.

License

The source code is released under:

MIT License

If you think the Android project UTHPortal-Android-Gradle 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.uth.uthportal.adapter;
/*from   w ww  .j  a v  a  2 s . co m*/
import java.util.HashMap;
import java.util.List;

import com.uth.uthportal.R;

import android.content.Context;
import android.graphics.Typeface;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
/**
 * This is the main adapter that is used for the lists.
 * It is based on expandable parent logic.
 * A HashMap is used to map a list of children to their parent.
 * @author GeorgeT
 *
 */
public class ExpandableListAdapter extends BaseExpandableListAdapter {
  
  private Context _context;
  private List<String> _listParentData; //the Parent elements
  private HashMap<String,List<String>> _listChildData; //the child elements
  // mapped like:   parent -> children.
  //constructor.!
  public ExpandableListAdapter(Context context, List<String> listParentData,
      HashMap<String,List<String>> listChildData){
    // we just set the class' properties through the constructor
    this._context = context;
    this._listParentData = listParentData;
    this._listChildData = listChildData;
  }
  @Override
  public Object getChild(int groupPosition, int childPosition) {
    return this._listChildData
        .get(this._listParentData
        .get(groupPosition))// <- here we have the list of children for that parent
        .get(childPosition); // <- we get the child we are interested in.
  }

  @Override
  public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
  }

  @Override
  public View getChildView(int groupPosition, int childPosition,
      boolean isLastChild, View convertView, ViewGroup parent) {
    
    final String childText = (String) getChild(groupPosition, childPosition);
    
    if (convertView == null){
      //if there's no view, we get the inflater and inflate the view.
      LayoutInflater lInflater = (LayoutInflater) this._context
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = lInflater.inflate(R.layout.list_sub_item,null);
    }
    //get the label we added in the layout.
    TextView textListChild = (TextView) convertView
        .findViewById(R.id.labelListChild);
    
    textListChild.setText(Html.fromHtml(childText));
    textListChild.setMovementMethod(LinkMovementMethod.getInstance());
    return convertView;
  }

  @Override
  public int getChildrenCount(int groupPosition) {
    return this._listChildData.get(this._listParentData
        .get(groupPosition)) //get the parent.
        .size(); //get its size.
  }

  @Override
  public Object getGroup(int groupPosition) {
    return this._listParentData.get(groupPosition);
  }

  @Override
  public int getGroupCount() {
    return this._listParentData.size();
  }

  @Override
  public long getGroupId(int groupPosition) {
    return groupPosition;
  }

  @Override
  public View getGroupView(int groupPosition, boolean isExpanded,
      View convertView, ViewGroup parent) {
    String parentTitle = (String) getGroup(groupPosition);
    
    if(convertView == null){
      // again same stuff
      LayoutInflater lInflater = (LayoutInflater) this._context
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = lInflater.inflate(R.layout.list_parent_item, null);
    }
    TextView labelListParent = (TextView) convertView
        .findViewById(R.id.labelListParent);
    labelListParent.setTypeface(null, Typeface.BOLD);
    labelListParent.setText(Html.fromHtml(parentTitle));
    
    return convertView;
  }

  @Override
  public boolean hasStableIds() {
    return false;
  }

  @Override
  public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
  }

}




Java Source Code List

com.uth.uthportal.AboutScreen.java
com.uth.uthportal.CoursesFragment.java
com.uth.uthportal.DepartmentFragment.java
com.uth.uthportal.FoodFragment.java
com.uth.uthportal.MainScreen.java
com.uth.uthportal.SettingsScreen.java
com.uth.uthportal.adapter.AdapterManager.java
com.uth.uthportal.adapter.AdapterProvider.java
com.uth.uthportal.adapter.ExpandableListAdapter.java
com.uth.uthportal.adapter.SettingsAdapter.java
com.uth.uthportal.adapter.TabsPagerAdapter.java
com.uth.uthportal.buffers.AvailableCoursesParser.java
com.uth.uthportal.buffers.CoursesParser.java
com.uth.uthportal.buffers.FileOperation.java
com.uth.uthportal.buffers.FoodParser.java
com.uth.uthportal.buffers.GeneralAnnParser.java
com.uth.uthportal.buffers.SettingsManager.java
com.uth.uthportal.collections.AnnItem.java
com.uth.uthportal.collections.Announcements.java
com.uth.uthportal.collections.AvailableCourse.java
com.uth.uthportal.collections.CourseInfo.java
com.uth.uthportal.collections.Course.java
com.uth.uthportal.collections.DayMenu.java
com.uth.uthportal.collections.DefaultIntervals.java
com.uth.uthportal.collections.Dish.java
com.uth.uthportal.collections.Food.java
com.uth.uthportal.collections.GeneralAnnouncement.java
com.uth.uthportal.collections.Settings.java
com.uth.uthportal.network.ApiLinks.java
com.uth.uthportal.network.AppRater.java
com.uth.uthportal.network.AsyncJSONDownloader.java
com.uth.uthportal.network.JSONDownloader.java
com.uth.uthportal.service.DataSyncService.java
com.uth.uthportal.util.SystemUiHiderBase.java
com.uth.uthportal.util.SystemUiHiderHoneycomb.java
com.uth.uthportal.util.SystemUiHider.java