Skip to content

Commit

Permalink
Improved performance of all ListViews
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh Joshi committed Jul 29, 2014
1 parent 379a05e commit 1fe9c3a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@ public DayByDayListAdapter ( Context ctx,int resid,Attendance[] att) {
this.att = att;
}

private class ViewHolder{
TextView date, status;
}

@Override
public View getView ( int position, View view, ViewGroup parent ) {
view = inflater.inflate(R.layout.day_by_day_list_item, null );
public View getView ( int position, View convertview, ViewGroup parent ) {
ViewHolder holder;
if(convertview == null){
convertview = inflater.inflate(R.layout.day_by_day_list_item, parent, false);
holder = new ViewHolder();
holder.date = (TextView) convertview.findViewById(R.id.atten_detail_date);
holder.status = (TextView) convertview.findViewById(R.id.atten_detail_status);
convertview.setTag(holder);
}
else
holder = (ViewHolder) convertview.getTag();

((TextView) view.findViewById(R.id.atten_detail_date)).setText(att[position].getDate());
TextView status = (TextView) view.findViewById(R.id.atten_detail_status);
status.setText(att[position].getStatus());
holder.date.setText(att[position].getDate());
holder.status.setText(att[position].getStatus());
if(att[position].getStatus().equals("Absent"))
status.setTextColor(Color.parseColor("#FF0000"));
return view;
holder.status.setTextColor(Color.parseColor("#FF0000"));

return convertview;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public View getView(int i, View view, ViewGroup viewGroup) {

//Check if the view is empty
if(vi==null)
vi = inflater.inflate(R.layout.drawer_list_item, null);
vi = inflater.inflate(R.layout.drawer_list_item, viewGroup, false);

TextView lbl_drawer = (TextView) vi.findViewById(R.id.lbl_drawer_title);
TextView lbl_drawer_sub = (TextView) vi.findViewById(R.id.lbl_drawer_subtitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,37 @@ public FullTTListAdapter(Context context, ArrayList<TTSlot> items){
mInflater = LayoutInflater.from(context);
dat = DataHandler.getInstance(context);
}

private class ViewHolder{
TextView slot, subject, venue, timing, att;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
convertView = mInflater.inflate(R.layout.fulltt_list_item,null);
ViewHolder holder;
if(convertView == null){
convertView = mInflater.inflate(R.layout.fulltt_list_item, parent, false);
holder = new ViewHolder();
holder.slot = ((TextView) convertView.findViewById(R.id.lbl_now_slot));
holder.subject = ((TextView) convertView.findViewById(R.id.lbl_now_subject));
holder.venue = ((TextView) convertView.findViewById(R.id.lbl_now_venue));
holder.timing = ((TextView) convertView.findViewById(R.id.lbl_now_timing));
holder.att = ((TextView) convertView.findViewById(R.id.lbl_now_att_now));
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();

TTSlot t = getItem(pos);
Subject subject = dat.getSubject(t.clsnbr);

SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mma", Locale.getDefault());

((TextView) convertView.findViewById(R.id.lbl_now_slot)).setText(t.slt);
((TextView) convertView.findViewById(R.id.lbl_now_subject)).setText(subject.title);
((TextView) convertView.findViewById(R.id.lbl_now_venue)).setText(t.venue);

TextView lbl_timing = (TextView) convertView.findViewById(R.id.lbl_now_timing);
TextView lbl_per = (TextView) convertView.findViewById(R.id.lbl_now_att_now);
holder.slot.setText(t.slt);
holder.subject.setText(subject.title);
holder.venue.setText(t.venue);

lbl_per.setText("Attendance: "+ subject.percentage + "%");
lbl_per.setTextColor(DataHandler.getPerColor(subject.percentage));
lbl_timing.setText(timeFormat.format(t.frm_time.getTime()) + " - " + timeFormat.format(t.to_time.getTime()));
holder.att.setText("Attendance: "+ subject.percentage + "%");
holder.att.setTextColor(DataHandler.getPerColor(subject.percentage));
holder.timing.setText(timeFormat.format(t.frm_time.getTime()) + " - " + timeFormat.format(t.to_time.getTime()));
return convertView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public int getItemViewType(int position) {

@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getItem(position).getView(mInflater, convertView);
return getItem(position).getView(mInflater, convertView,parent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by saurabh on 4/24/14.
*/
public interface NowItem {
public int getViewType();
public View getView(LayoutInflater inflater, View convertView);
public View getView(LayoutInflater inflater, View convertView, ViewGroup parent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.karthikb351.vitinfo2.R;
Expand All @@ -25,11 +26,11 @@ public int getViewType() {
}

@Override
public View getView(LayoutInflater inflater, View convertView) {
public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) {
View view;

if(convertView == null)
view = inflater.inflate(R.layout.now_list_item_header, null);
view = inflater.inflate(R.layout.now_list_item_header, parent, false);
else
view = convertView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.karthikb351.vitinfo2.R;
Expand Down Expand Up @@ -33,10 +34,10 @@ public int getViewType() {
}

@Override
public View getView(LayoutInflater inflater, View convertView) {
public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) {
View view;
if(convertView == null)
view = inflater.inflate(R.layout.now_list_item_now, null);
view = inflater.inflate(R.layout.now_list_item_now, parent, false);
else
view = convertView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.karthikb351.vitinfo2.R;

Expand All @@ -18,10 +19,10 @@ public int getViewType() {
}

@Override
public View getView(LayoutInflater inflater, View convertView) {
public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) {
View view;
/* TODO: Make the textView exactly at center of image in the XML */
view = inflater.inflate(R.layout.now_list_item_noclass,null);
view = inflater.inflate(R.layout.now_list_item_noclass,parent, false);
return view;
}
}

0 comments on commit 1fe9c3a

Please sign in to comment.