Back to project page UTHPortal-Android-Gradle.
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.
package com.uth.uthportal.adapter; /*from w ww . j ava2s . co m*/ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.uth.uthportal.R; import com.uth.uthportal.collections.AvailableCourse; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.TextView; /** * This adapter is used for listing available courses * with a check box next to them. * @author GeorgeT * */ public class SettingsAdapter extends ArrayAdapter<AvailableCourse>{ List<AvailableCourse> availableCoursesList; Context _context; public SettingsAdapter(Context context, int resource, List<AvailableCourse> objects) { super(context, resource, objects); availableCoursesList = new ArrayList<AvailableCourse>(); //Initialize list availableCoursesList.addAll(objects); //clone list _context = context; } private class ViewHolder{ TextView code; CheckBox name; } public List<String> getCheckedCourses(){ List<String> result = new ArrayList<String>(); for (AvailableCourse course : availableCoursesList) { if (course.getAnnouncements) result.add(course.code); } return result; } @Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder = null; Log.v("ConvertView", String.valueOf(position)); if (convertView == null) { LayoutInflater vi = (LayoutInflater)this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); //get system layout inflater service convertView = vi.inflate(R.layout.list_settings_item, null); holder = new ViewHolder(); holder.code = (TextView) convertView.findViewById(R.id.settingsCourseCode); holder.name = (CheckBox) convertView.findViewById(R.id.settingsCourseCheck); convertView.setTag(holder); holder.name.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) { String text = buttonView.getText().toString(); for (AvailableCourse course : availableCoursesList) { if (course.info.name.equals(text)) course.getAnnouncements = isChecked; } } }); holder.code.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { TextView textView = (TextView)v; Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(textView.getText().toString())); _context.startActivity(browserIntent); } }); } else { holder = (ViewHolder) convertView.getTag(); } AvailableCourse course = availableCoursesList.get(position); //get the course at position of list holder.code.setText(" (" + course.code + ")"); holder.name.setText(course.info.name); holder.name.setChecked(course.getAnnouncements); holder.name.setTag(course); return convertView; } }